Go to Post There are NO old, bold electrical engineers! - Al Skierkiewicz [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
  #16   Spotlight this post!  
Unread 01-02-2013, 14:12
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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
OK, so do this instead:

Code:
output = (719 % 360 > 180) ? (-360 + (719 % 360)) : (719 % 360);
Fails when angle = -359. Doesn't work with floats.


Reply With Quote
  #17   Spotlight this post!  
Unread 01-02-2013, 14:16
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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 sur View Post
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);
Would you mind running that and see if it produces the same output as this:

Code:
double myRemainder(double x, double y){
return x-y*floor(0.5+x/y);
}


Reply With Quote
  #18   Spotlight this post!  
Unread 01-02-2013, 15:12
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

What about:

Code:
double EthersRemainder( double x, double y ){

int wholenumber;

wholenumber = (int)(x/y);

double result;

result = (x - (wholenumber * y));
if(result > 0.5*y) {
result -= y;
}

return result;

}
Reply With Quote
  #19   Spotlight this post!  
Unread 01-02-2013, 15:41
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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
What about:
EthersRemainder
That's not my remainder.

Did you compile and run it ? It doesn't work correctly.

I'm sure that there's a way, with enough conditional logic, to torture fmod() or % into into a remainder* function, but what I am really asking in this thread is

a) does the C++ compiler provided with FRC have the remainder* function, and

b) does it behave like this:


*This* is my remainder:

Code:
double myRemainder(double x, double y){
  return x-y*floor(0.5+x/y);
}

*per IEC 60559 as specified on Page 235 Section 7.12.10.2 of ISO/IEC 9899:TC3


Last edited by Ether : 01-02-2013 at 16:11.
Reply With Quote
  #20   Spotlight this post!  
Unread 01-02-2013, 17:23
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

If you have a function that works, then use it?

I don't understand your qualm?

I have not ever encountered a programming scenario where modulus division didn't solve my desire for a remainder, so I'm a bit lost.

If there doesn't exist an operator that does what you want, then you need to either a) fabricate a solution from the operators you have access to, or b) find a library that does that for you.
Reply With Quote
  #21   Spotlight this post!  
Unread 01-02-2013, 18:16
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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
If you have a function that works, then use it?
I do use it. But I don't want to be telling other people to use my custom function if there's already a perfectly good remainder function provided with FRC C++. I don't have access to a working C++ installation, otherwise I would test it myself. I am seeking help from knowledgeable C++ users on this forum.

Quote:
I don't understand your qualm?
Honestly, that's because I don't have a qualm. I am perfectly calm.

Quote:
I have not ever encountered a programming scenario where modulus division didn't solve my desire for a remainder, so I'm a bit lost.
I have encounted at least one such scenario, and that's why I posted this thread.

For example, the IEC60559 remainder function can take any angle and normalize it to the range -180..+180 with a single C instruction:

normalizedAngle = remainder(angle,360);

I'd like to know if the remainder function is supported in FRC C++ so I can recommend it to students who are trying to do this type of conversion.

Neither the fmod() function nor the % operator can replicate the functionality of the remainder() function without using a bunch of conditional logic

If there are any Java programmers following this thread, Java appears to have the IEC 60559 remainder function; in Java it is called IEEERemainder. See attachments. If someone would be willing to test that (compare it to the implementation I posted ealier in this thread) I'd be grateful.



qualm
/kwä(l)m/
Noun

1) An uneasy feeling of doubt, worry, or fear; a misgiving.
2) A momentary faint or sick feeling.

Synonyms
nausea - queasiness
Attached Thumbnails
Click image for larger version

Name:	Java_IEEEremainder.png
Views:	19
Size:	6.2 KB
ID:	13749  Click image for larger version

Name:	20.11.14.png
Views:	19
Size:	9.8 KB
ID:	13750  
Reply With Quote
  #22   Spotlight this post!  
Unread 01-02-2013, 19:06
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: remainder function

In a Java SE project this
Code:
        double result;
        double x[] = {179, 180, 181, 359, 721, -1, -179, -180, -359, -361, -721};

        for (int i = 0; i < x.length; i++){
            result = Math.IEEEremainder(x[i],360.0); 
            System.out.println("x: " + x[i] + " rem y: 360 result: " + result);
        }
yields this:
Code:
x: 179.0 rem y: 360 result: 179.0
x: 180.0 rem y: 360 result: 180.0
x: 181.0 rem y: 360 result: -179.0
x: 359.0 rem y: 360 result: -1.0
x: 721.0 rem y: 360 result: 1.0
x: -1.0 rem y: 360 result: -1.0
x: -179.0 rem y: 360 result: -179.0
x: -180.0 rem y: 360 result: -180.0
x: -359.0 rem y: 360 result: 1.0
x: -361.0 rem y: 360 result: -1.0
x: -721.0 rem y: 360 result: -1.0
which I believe is what you are looking for.

However I cannot use IEEERemainder() in an FRC project they have compiled the jar without it apparently.

Last edited by omalleyj : 01-02-2013 at 19:16. Reason: still can't spell after all these years
Reply With Quote
  #23   Spotlight this post!  
Unread 01-02-2013, 20:23
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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 omalleyj View Post
In a Java SE project this

[snip]

yields this:

[snip]

which I believe is what you are looking for.
Excellent. Thank you! I'd give you some more reps, but it won't let me

Quote:
However I cannot use IEEERemainder() in an FRC project they have compiled the jar without it apparently.
Not being a Java user, I'm not sure what that means. Is there a way to re-compile to include it, or is that a major undertaking?


Are there any C++ gurus out there who can look into the same question for C++ ?


Reply With Quote
  #24   Spotlight this post!  
Unread 01-02-2013, 20:34
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: remainder function

Quote:
Originally Posted by omalleyj View Post
However I cannot use IEEERemainder() in an FRC project they have compiled the jar without it apparently.
That's not entirely true. FRC uses the Squawk JVM, which is based on Java ME. Java ME does not require IEEERemainder(), which is why it isn't in java.lang.Math. However, Squawk does implement some features from Java SE, and puts them in other packages. In this case, IEEERemainder is in the com.sun.squawk.util.MathUtils package.

Last edited by Joe Ross : 01-02-2013 at 20:42.
Reply With Quote
  #25   Spotlight this post!  
Unread 01-02-2013, 20:39
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: remainder function

Thanks!
Is there a cross reference of where SE stuff that's been moved can be found?

Last edited by omalleyj : 01-02-2013 at 20:46. Reason: added a question
Reply With Quote
  #26   Spotlight this post!  
Unread 01-02-2013, 20:49
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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 Joe Ross View Post
That's not entirely true. FRC uses the Squawk JVM, which is based on Java ME. Java ME does not require IEEERemainder(), which is why it isn't in java.lang.Math. However, Squawk does implement some features from Java SE, and puts them in other packages. In this case, IEEERemainder is in the com.sun.squawk.util.MathUtils package.
Joe, you never cease to amaze me


Reply With Quote
  #27   Spotlight this post!  
Unread 01-02-2013, 21:54
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: remainder function

Here's the result from the robot

Code:
        double result;
        double x[] = {179, 180, 181, 359, 721, -1, -179, -180, -359, -361, -721};

        for (int i = 0; i < x.length; i++){
            result = MathUtils.IEEEremainder(x[i],360.0); 
            System.out.println("x: " + x[i] + " rem y: 360 result: " + result);
        }
Quote:
[cRIO] x: 179.0 rem y: 360 result: 179.0
[cRIO] x: 180.0 rem y: 360 result: 180.0
[cRIO] x: 181.0 rem y: 360 result: -179.0
[cRIO] x: 359.0 rem y: 360 result: -1.0
[cRIO] x: 721.0 rem y: 360 result: 1.0
[cRIO] x: -1.0 rem y: 360 result: -1.0
[cRIO] x: -179.0 rem y: 360 result: -179.0
[cRIO] x: -180.0 rem y: 360 result: -180.0
[cRIO] x: -359.0 rem y: 360 result: 1.0
[cRIO] x: -361.0 rem y: 360 result: -1.0
[cRIO] x: -721.0 rem y: 360 result: -1.0
Reply With Quote
  #28   Spotlight this post!  
Unread 01-02-2013, 21:55
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: remainder function

Quote:
Originally Posted by omalleyj View Post
Thanks!
Is there a cross reference of where SE stuff that's been moved can be found?
It's all in the javadocs, but I'm not aware of an easy cross reference.
Reply With Quote
  #29   Spotlight this post!  
Unread 01-02-2013, 22:17
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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 Joe Ross View Post
Here's the result from the robot
Bingo! They match.


Reply With Quote
  #30   Spotlight this post!  
Unread 02-02-2013, 02:16
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: remainder function

From my installation, a grep through the headers folder shows no remainder functions. It's possible I'm missing something, but it looks like it doesn't exist at all in the vxWorks API.

As for the extern "C" option, yes that will make it compile, however the function will most likely not be resolved by the linker, which will cause problems when you try to run it. Wind River's system is designed to not complain about missing symbols until the cRIO's kernel tries to load the program. I'll check if this is the case tomorrow.

EDIT: actually, drem() does exist, and is defined to be the same as remainder() (see the glibc manual). However, the definition for it is in <private/trigP.h>, which isn't meant for inclusion by user programs. There don't seem to be any public headers which include it either.
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"

Last edited by Radical Pi : 02-02-2013 at 02:37.
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 13:37.

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