2

In C++ C: Output: "1610612736"

#include <math.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    printf("%d\n", fmodf(5.6f, 6.4f));
    getchar();
}

In C#: Output: "5.6"

using System;

static class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(5.6f % 6.4f);
        Console.Read();
    }
}

Clearly not the same output. Suggestions?

Timwi
  • 65,159
  • 33
  • 165
  • 230
Lazlo
  • 8,518
  • 14
  • 77
  • 116

2 Answers2

5

Try with printf("%f\n", fmodf(5.6f, 6.4f)) instead.

Alexandre C.
  • 55,948
  • 11
  • 128
  • 197
0

Correcting the decimal problem with fprintf()

#include <math.h>
#include <stdio.h>
#include <iostream>

int main(int argc, char** argv)
{
    std::cout << fmodf(5.6f, 6.4f) << std::endl;
    getchar();
}

Output 5.6

Martin York
  • 257,169
  • 86
  • 333
  • 562
  • 2
    Please use and , I'm quite sure the C headers trigger errors (or deprecation warnings at the very least) on most compilers. And please use the overloaded function `std::fmod` instead of C's `fmodf`. – Alexandre C. Sep 08 '10 at 23:15