Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   remainder function (http://www.chiefdelphi.com/forums/showthread.php?t=112483)

Ether 02-02-2013 10:06

Re: remainder function
 
Quote:

Originally Posted by Radical Pi (Post 1226275)
drem() does exist, and is defined to be the same as remainder() (see the glibc manual).

Apparently in glibc, remainder() and drem() are two different names for the same function

Notice the very slight difference between the glibc and Java definitions (handling of divide-by-zero).



nightpool 02-02-2013 11:14

Re: remainder function
 
The "java" link you posted was to gnu libc...

Ether 02-02-2013 11:27

Re: remainder function
 
Quote:

Originally Posted by nightpool (Post 1226357)
The "java" link you posted was to gnu libc...

Fixed. Take a look.



Ether 08-02-2015 16:56

Re: remainder function
 
Quote:

Originally Posted by Joe Ross (Post 1226192)
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);
        }


Joe, is the MathUtils.IEEEremainder() method available in 2015 FRC Java, now that the runtime engine has changed? If so, does it produce the exact same results?



Joe Ross 08-02-2015 17:32

Re: remainder function
 
Quote:

Originally Posted by Ether (Post 1440331)
Joe, is the MathUtils.IEEEremainder() method available in 2015 FRC Java, now that the runtime engine has changed? If so, does it produce the exact same results?



It's in Math, rather then the squawk MathUtils workaround, but it still works.

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


Ether 08-02-2015 19:00

Re: remainder function
 
Quote:

Originally Posted by Joe Ross (Post 1440349)

It's in Math, rather then the squawk MathUtils workaround, but it still works.


Thanks Joe.

For those of you reading this thread for the first time, Math.IEEEremainder(angle,360.0) can be used to convert any angle (in degrees) to the range -180 to 180.

This can be very useful when working with the gyro.

Let's say you want to find the shortest angular error between your joystick direction angle and the gyro angle. This can be accomplished in one clean line of code as follows:

angle_error = Math.IEEEremainder(joystick-gyro,360.0);

There's no need for conditional logic. It cleanly handles all input angle ranges for joystick and gyro, including angles greater than 360 degrees and less than -360 degrees.

The above assumes that gyro and joystick share the same zero and measurement direction.




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

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