In C #, is there an exact equivalent to the C99 / IEEE 754 function remainder()?
The C # language specification says it operator %(double x, double y)is "similar to that used for integer operands, but different from the IEEE 754 definition (which nis the integer closest to x / y)."
For an example of the difference, this C # program outputs two characters 1:
using System;
public class Test
{
public static void Main()
{
Console.WriteLine(5.0 % 2.0);
Console.WriteLine(3.0 % 2.0);
}
}
http://ideone.com/GBITYq
whereas a similar program C produces 1 and -1:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("%f\n", remainder(5.0, 2.0));
printf("%f\n", remainder(3.0, 2.0));
return EXIT_SUCCESS;
}
http://ideone.com/HpuIVr
source
share