# From -PI...PI wrapper

**URL:** <https://forum.kirupa.com/t/from-pi-pi-wrapper/314805>\
**Category:** Uncategorized\
**Created:** [October 9, 2010, 4:00am UTC](https://forum.kirupa.com/t/from-pi-pi-wrapper/314805 "2010-10-09T04:00:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coreman2200](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@coreman2200](https://forum.kirupa.com/u/coreman2200)\
**Post date:** [October 9, 2010, 4:00am UTC](https://forum.kirupa.com/t/from-pi-pi-wrapper/314805/1 "2010-10-09T04:00:32Z")

</div>

Hello all 🙂

So I’ve been looking into faster sin/cos functions lately and found code for a faster method than Math… that I’ve come to adopt in my code. Thing is, bit of code requires that the input value be between -PI…PI. Their suggestion was an if/then that would add/ subtract 2\*PI… Which meant that that would have to be in a while loop, too, (while value \> PI…) until it is within range. Considering that I’m trying to optimize/speed up calls to sin/cos, that’d kinda defeat the purpose. So I took it upon myself to figure it out in one blow:

```auto

// xx = input value in radians
var Sign:Number = ((xx < 0) ? -1 : 1); // if input value is +/-...
/* xx is brought within realms of -PI..PI:
   -Pi * 
         (1 if xx/Pi is odd, ie wraps back towards -PI ; 0 if even, ie tends to +PI )
   + xx mod pi (remainder, will be +/- depending on orig value of xx); */

// So we have...
xx = (-Sign*PI * (int(xx / PI) & 1)) + ( xx % PI); 

```

Now. I’d like to know if that is an efficient/effective/practical method, or if there’s an easier way to get that value than what I’ve devised, as I’m hardly either mathematically or computer logically savvy lol, and I figure that I’ve gone a bit overkill and there’s actually a simpler way to do this. Any help/hints/tips would be appreciated!
