News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

remainder function

Started by Griffin, October 12, 2018, 04:40:37 PM

Previous topic - Next topic

Griffin

Allright, this is strange.

remainder( 0.11, 0.2 ) returns -0.09000. That can't be right, no?

Test case:
---------------8<------------------
#include <stdio.h>
#include <math.h>

int main( void )
{
    printf( "Remainder = %f\n", remainder( 0.11, 0.2 ) );
}

AlexN

I tried GCC with the same result.
best regards
Alex ;)

jack

it may be that you have a misunderstanding of the function
from The GNU C Library documentation
Quote
Function: double remainder (double numerator, double denominator)
These functions are like fmod except that they round the internal quotient n to the nearest integer instead of towards zero to an integer. For example, remainder (6.5, 2.3) returns -0.4, which is 6.5 minus 6.9.

The absolute value of the result is less than or equal to half the absolute value of the denominator. The difference between fmod (numerator, denominator) and remainder (numerator, denominator) is always either denominator, minus denominator, or zero.

If denominator is zero, remainder signals a domain error.

Pelle

The result seems correct. The help file doesn't say much, it only echoes what the C standard says. If I find myself having a really great day (unlikely), I may improve the text for this function...
/Pelle