Degrees

BlitzMax Forums/BlitzMax Beginners Area/Degrees

JBR(Posted 2015) [#1]
Hi, I have a value 'degrees#' which could be any value.

What is the best way to make it between 0.0 and 359.9999999...

But still the same if you know what I mean.


GfK(Posted 2015) [#2]
degrees:Mod 360


which is the same as
degrees = degrees Mod 360


Example
degrees = 365
degrees:Mod 360

Result = 5.


JBR(Posted 2015) [#3]
Gfk does Mod not work only on integers?

Need floating point.


GfK(Posted 2015) [#4]
Gfk does Mod not work only on integers?

Nope, it'll work fine.


Floyd(Posted 2015) [#5]
It does, however, return results in the range -360 to +360.

A Mod M will have the same sign as A. So if you want 0 to 360 you can do A Mod 360 and test the result. If negative then add 360.

Another possibility is ( ( A Mod 360) + 360 ) Mod 360. The + 360 ensures a non-negative value.


JBR(Posted 2015) [#6]
Thanks