Problems negating a number
reppig
Posts: 35
When I run the following code cos_lon evaluates correctly to 0.1618761.
However, neg_cos_lon evaluates to -27.27986 not -0.1618761 which is what I want??
I also tried what was in the manual -neg_cos_lon and I got the same wrong answer.
However, neg_cos_lon evaluates to -27.27986 not -0.1618761 which is what I want??
I also tried what was in the manual -neg_cos_lon and I got the same wrong answer.
cos_lon := f.Cos(f.Radians(gs_lon)) neg_cos_lon := -cos_lon DBG.Str(FS.FloatToString(cos_lon)) DBG.Str(STRING(" ")) DBG.Str(FS.FloatToString(neg_cos_lon))
Comments
-Phil
Like:
neg_cos_lon := cos_lon ^ $8000_0000
Much faster than a floating point operation, and I can't think of a scenario where it would give you incorrect results (though I'm no expert on floating point).
-Phil
The problem with negating a float, when it thinks it is a integer is because the bit structure for an integer of negative and positive 5 (for example) is completely different from each other (%11111111111111111111111111111011 vs %00000000000000000000000000000101), most of the bits get changed. Where as a floating point number, the difference is very simple (%11000000101100011100001010010000 vs %01000000101100011100001010010000), just bit 31 changes.