Math: Tangent
Displaying 1-6 of 6 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Omni

Is something wrong with Tangent? Outside of its range (0 > X < 90, 180 > X < 270) it returns the most bizarre values that do not conform to 16.16 fixed point.

I mean, technically it's not functionally broken, as when it works, it works. But why does it return a value at all in those regions? It was slightly annoying...

Posted on 2005-10-31 18:30:49

Jesse

I'm not sure what you're asking. tan() is defined over all values, except for when cos(theta) == 0. At those points, it looks like it returns a large negative value (since it should be returning +/- infinity.) Would you rather it gave an error and quit?

Posted on 2005-11-01 10:22:41

Omni

Well, all I know is, whenever I do Tangent on an angle, for example, greater than/equal to 90, less than 180, I get really weird negative numbers that are definitely outside 16.16 fixed range [which I assume, in our case, Tan being a ratio...

Er, you know what, forget everything I said. I obviously forgot that Tangent can be greater than 1, due to it being a ratio between Sin/Cos (which only range from -1 to 1). In addition, I mistook 16.16-fixed point for the lower half/decimal 65536, forgetting there was a whole 65536 in the whole number region.

By the way...does 16.16 fixed point literally mean "sixteen bits integer, sixteen bits decimal?"

Posted on 2005-11-01 17:37:26

Jesse

16.16 fixed point means that if you divide the integer by 2^16 == 65536, you would get the actual value. So, effectively, yes, you have 16 bits to the right of the decimal, but that doesn't mean that the lower 16 bits, interpreted as an int, would give you the value to the right of the decimal. Like, for the value 1.1, the lower 16 bits would not be 1, they would be .1 * 2^16 = 6554. Make sense?

Posted on 2005-11-01 19:16:12

Omni

I understand what you are saying...I was almost confused for a second that you meant the lower 16 bits could only hold values from 0 to 0.1,

but what you were saying was that...

lower 16 bits = [real float value to right of decimal] * 2^16

Right? That makes good sense. In each case though, I still have all the data I need to determine the value of the decimal portion in the lower 16 bits, right?

Posted on 2005-11-02 09:37:09

Jesse

Yes, exactly. The decimal value of the lower 16 bits should be possible to extract. For example, to get it truncated to x decimal places, the following should work:

int wholeValue = float >> 16;
int decValue = ((float - (wholeValue << 16)) * pow(10,x)) >> 16;


So you could then do something like:

MessageBox("Value: " + str(wholeValue) + "." + str(decValue));

Posted on 2005-11-02 10:02:24 (last edited on 2005-11-02 10:19:24)


Displaying 1-6 of 6 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.