[ create a new paste ] login | about

Link: http://codepad.org/UOgEqAMA    [ raw code | output | fork ]

spud - C++, pasted on Oct 23:
#include <math.h>

float ZZZ_fmodf(float a, float N)
{
	//assert(N>0);
	
	// 10.8 mod 2, floor (5.4) = 5 ... 10.8 - 5*2 = .8 YES
	// -10.8 mod 2, floor (-5.4) = -6 ... -10.8 - (-6*2) = 1.2 YES
	
        float ret = a - N * floor (a / N);

        printf("%f ZZZ_fmodf %f = %f \n", a, N, ret);

        return ret;
}

int main (char* argc, char** argv)
{
        float x = fmodf(-10.2f, 2.0f);
        printf ("fmodf(-10.2f, 2.0f) = %f  == FAIL! \n", x);

        x = ZZZ_fmodf(10.2f, 2.0f);
        x = ZZZ_fmodf(10.2f, -2.0f);
        x = ZZZ_fmodf(-10.2f, 2.0f);
        x = ZZZ_fmodf(-10.2f, -2.0f);

        return 0;
}


Output:
1
2
3
4
5
fmodf(-10.2f, 2.0f) = -0.200000  == FAIL! 
10.200000 ZZZ_fmodf 2.000000 = 0.200000 
10.200000 ZZZ_fmodf -2.000000 = -1.800000 
-10.200000 ZZZ_fmodf 2.000000 = 1.800000 
-10.200000 ZZZ_fmodf -2.000000 = -0.200000 


Create a new paste based on this one


Comments: