Go to Post "We used to shut the robot up in a box and send it away from home. Now we just suffocate it." - GaryVoshol [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 31-01-2013, 18:38
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
remainder function


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.


Attached Thumbnails
Click image for larger version

Name:	remainder.png
Views:	63
Size:	63.8 KB
ID:	13738  

Last edited by Ether : 31-01-2013 at 18:47. Reason: added screenshot
Reply With Quote
  #2   Spotlight this post!  
Unread 31-01-2013, 22:48
sur sur is offline
Registered User
AKA: Sujit Rao
FRC #3324 (Metrobots)
Team Role: Alumni
 
Join Date: May 2012
Rookie Year: 2011
Location: Ohio
Posts: 12
sur is an unknown quantity at this point
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
Reply With Quote
  #3   Spotlight this post!  
Unread 01-02-2013, 00:41
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
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
 181.000     -179.000      181.000
-181.000      179.000     -181.000
 359.000       -1.000      359.000
-359.000        1.000     -359.000
 719.000       -1.000      359.000
-719.000        1.000     -359.000


Reply With Quote
  #4   Spotlight this post!  
Unread 01-02-2013, 09:18
nightpool's Avatar
nightpool nightpool is offline
robotRectifier
AKA: Evan
no team (formerly of CORE 2062)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 81
nightpool is on a distinguished road
Re: remainder function

What's the issue with using the modulus operator instead of the built-in remainder function?
__________________
Proud alum of CORE 2062.
www.core2062.com
Reply With Quote
  #5   Spotlight this post!  
Unread 01-02-2013, 09:24
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: remainder function

Quote:
Originally Posted by nightpool View Post
What's the issue with using the modulus operator instead of the built-in remainder function?
Are you saying there is a remainder function in the C++ compiler used for FRC?


Reply With Quote
  #6   Spotlight this post!  
Unread 01-02-2013, 11:54
sur sur is offline
Registered User
AKA: Sujit Rao
FRC #3324 (Metrobots)
Team Role: Alumni
 
Join Date: May 2012
Rookie Year: 2011
Location: Ohio
Posts: 12
sur is an unknown quantity at this point
Re: remainder function

It looks like you need to define it using extern "C" for WindRiver to compile it correctly:

Code:
#include <cmath>
using namespace std;

extern "C" double remainder(double, double);
Reply With Quote
  #7   Spotlight this post!  
Unread 01-02-2013, 12:35
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
Re: remainder function

Quote:
Originally Posted by Ether View Post
Are you saying there is a remainder function in the C++ compiler used for FRC?


There's definitely a modulus division operator, which amounts to the same thing.

719 % 360 = 359
Reply With Quote
  #8   Spotlight this post!  
Unread 01-02-2013, 12:57
nightpool's Avatar
nightpool nightpool is offline
robotRectifier
AKA: Evan
no team (formerly of CORE 2062)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 81
nightpool is on a distinguished road
Re: remainder function

Quote:
Originally Posted by 1075guy View Post
There's definitely a modulus division operator, which amounts to the same thing.

719 % 360 = 359
Right, but it rounds the same as fmod() (see http://www.gnu.org/software/libc/man...Functions.html). I don't have enough experience to say when this would be more or less useful in practice, but if you DO need it extern "C" seems to be the way to go about it.
__________________
Proud alum of CORE 2062.
www.core2062.com
Reply With Quote
  #9   Spotlight this post!  
Unread 01-02-2013, 13:01
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: remainder function

Quote:
Originally Posted by 1075guy View Post
There's definitely a modulus division operator, which amounts to the same thing.

719 % 360 = 359
The modulus division operator is *not* the same thing as the remainder function.

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.



Reply With Quote
  #10   Spotlight this post!  
Unread 01-02-2013, 13:21
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
Re: remainder function

OK, so do this instead:

Code:
output = (719 % 360 > 180) ? (-360 + (719 % 360)) : (719 % 360);
Reply With Quote
  #11   Spotlight this post!  
Unread 01-02-2013, 13:38
Cal578 Cal578 is offline
Passionate FIRST-er, CD donor
AKA: Gerry
FRC #0578 (Red Raider Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Rochester, NY
Posts: 255
Cal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant future
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.
__________________
Cal
R3: Red Raider Robotics (FRC Team 578)
Fairport, NY, USA
www.FairportRobotics.org
2016 Finger Lakes Regional: Semifinalist on Alliance 7 (1128, 2010, 578)
2016 NYC Regional: Finalist on Alliance 3 (3419, 578, 3017), 4th seed team, Team Spirit Award
2015 Finger Lakes Regional: 8-3-0 in qualification, 7th seed, Quarterfinalist
2014 NY Tech Valley Regional: 8-4-0 in qualification, 13th seed, Semifinalist
2013 Finger Lakes Regional: 4-5-0 in qualification, 26th seed, Alliance 6, 1-2 in tournament
2012 Buckeye Regional: Gracious Professionalism Award, 7-3-0, 14th seed
2011 Finger Lakes Regional: Engineering Inspiration Award
Reply With Quote
  #12   Spotlight this post!  
Unread 01-02-2013, 13:40
nightpool's Avatar
nightpool nightpool is offline
robotRectifier
AKA: Evan
no team (formerly of CORE 2062)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 81
nightpool is on a distinguished road
Re: remainder function

The "normal" name for this function is drem(), which I think is a contraction of d-something and remainder.
__________________
Proud alum of CORE 2062.
www.core2062.com
Reply With Quote
  #13   Spotlight this post!  
Unread 01-02-2013, 13:45
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: remainder function

Quote:
Originally Posted by nightpool View Post
The "normal" name for this function is drem()
"Normal" according to whom? Link please.


Reply With Quote
  #14   Spotlight this post!  
Unread 01-02-2013, 13:47
Cal578 Cal578 is offline
Passionate FIRST-er, CD donor
AKA: Gerry
FRC #0578 (Red Raider Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Rochester, NY
Posts: 255
Cal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant futureCal578 has a brilliant future
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.
__________________
Cal
R3: Red Raider Robotics (FRC Team 578)
Fairport, NY, USA
www.FairportRobotics.org
2016 Finger Lakes Regional: Semifinalist on Alliance 7 (1128, 2010, 578)
2016 NYC Regional: Finalist on Alliance 3 (3419, 578, 3017), 4th seed team, Team Spirit Award
2015 Finger Lakes Regional: 8-3-0 in qualification, 7th seed, Quarterfinalist
2014 NY Tech Valley Regional: 8-4-0 in qualification, 13th seed, Semifinalist
2013 Finger Lakes Regional: 4-5-0 in qualification, 26th seed, Alliance 6, 1-2 in tournament
2012 Buckeye Regional: Gracious Professionalism Award, 7-3-0, 14th seed
2011 Finger Lakes Regional: Engineering Inspiration Award
Reply With Quote
  #15   Spotlight this post!  
Unread 01-02-2013, 13:55
nightpool's Avatar
nightpool nightpool is offline
robotRectifier
AKA: Evan
no team (formerly of CORE 2062)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 81
nightpool is on a distinguished road
Re: remainder function

GNU libc. See the link in my previous post.
__________________
Proud alum of CORE 2062.
www.core2062.com
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:29.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi