![]() |
remainder function
1 Attachment(s)
Does the C++ compiler used for FRC support the REMAINDER operator "x REM y" per IEC 60559 as specified on Page 235 Section 7.12.10.2 of ISO/IEC 9899:TC3 ? If someone would be willing to test that with y=360 and x values of 179, 180, 181, 359, 721, -1, -179, -180, -359, -361, -721 and post results it would be much appreciated. |
Re: remainder function
It seems to be defined if you use the C compiler, but not the C++ one. You could use fmod, which has slightly different behavior.
You can test it out here: http://codepad.org/86MlmNXU |
Re: remainder function
fmod(x,y) is quite different from remainder(x,y) The 3 columns below are x, remainder(x,360), and fmod(360): Code:
180.000 -180.000 180.000 |
Re: remainder function
What's the issue with using the modulus operator instead of the built-in remainder function?
|
Re: remainder function
Quote:
|
Re: remainder function
It looks like you need to define it using extern "C" for WindRiver to compile it correctly:
Code:
#include <cmath> |
Re: remainder function
Quote:
719 % 360 = 359 |
Re: remainder function
Quote:
|
Re: remainder function
Quote:
remainder(719,360) is -1, not 359. Look at the definition of the remainder function which I attached to the original post in this thread. |
Re: remainder function
OK, so do this instead:
Code:
output = (719 % 360 > 180) ? (-360 + (719 % 360)) : (719 % 360); |
Re: remainder function
I can see how the remainder function would be useful in certain cases, except that I don't like the name of the function. It's non-intuitive, and the results would surprise many people who look at the code after the original writer. When I think back to when I learned division in elementary school, the remainder of two positive numbers was always positive (or zero). I'm trying to think of what I would have named that function, to be more in line with its return values.
|
Re: remainder function
The "normal" name for this function is drem(), which I think is a contraction of d-something and remainder.
|
Re: remainder function
Quote:
|
Re: remainder function
"Delta Remainder" sounds cool. At least when I see drem, I would expect slightly different behavior, thus obeying the programming law of Minimize Surprise.
|
Re: remainder function
GNU libc. See the link in my previous post.
|
| All times are GMT -5. The time now is 09:29 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi