### Author Topic: remainder function  (Read 614 times)

#### Griffin

• Member
• Posts: 3
##### remainder function
« on: October 12, 2018, 04:40:37 pm »
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 ) );
}
« Last Edit: October 12, 2018, 04:42:53 pm by Griffin »

#### AlexN

• Global Moderator
• Member
• Posts: 383
##### Re: remainder function
« Reply #1 on: October 12, 2018, 06:34:42 pm »
I tried GCC with the same result.
best regards
Alex

#### jack

• Member
• Posts: 60
##### Re: remainder function
« Reply #2 on: October 12, 2018, 07:16:05 pm »
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.