VBForums - Assembly
https://www.vbforums.com/
Questions and Answers for Assembly here!enWed, 14 Aug 2024 00:48:05 GMTvBulletin60https://www.vbforums.com/images/misc/rss.pngVBForums - Assembly
https://www.vbforums.com/
How is a power_of_two calculated in x87 assembly?
https://www.vbforums.com/showthread.php?905409-How-is-a-power_of_two-calculated-in-x87-assembly&goto=newpost
Mon, 15 Jul 2024 10:27:45 GMTThe x87 floating point instructions have the F2XM1 instruction, which would seem to be what you want. It's supposed to calculate (2^x)-1 from which you should be able to easily calculate 2^x by simply then adding 1 to the result of the F2XM1 instruction. However when I look at this https://www.felixcloutier.com/x86/f2xm1 it makes it clear that the exponent has a VERY limited range from -1 to 1. If you want an exponent smaller than -1 or larger than 1, you are out of luck. Not entirely though because of the FSCALE instruction, but reading up about that instruction at https://www.felixcloutier.com/x86/fscale makes it very clear that the exponent must be an integer value. So now we have one instruction that allows floating point exponents but only between -1 and 1, and another instruction that allows any arbitrarily large or small exponent but it's limited to being an integer valued exponent. Why is there no instruction that allows arbitrarily large and small exponents while NOT imposing an integer restriction? I know that computers can do math that involves raising 2 to any arbitrary floating-point valued exponent (in fact computers can do math with any arbitrary base as well), but how the computer is doing such math I don't know. There don't seem to be any actual floating point instructions for arbitrary exponents, even when talking about limiting the base to only being 2.
]]>AssemblyBen321https://www.vbforums.com/showthread.php?905409-How-is-a-power_of_two-calculated-in-x87-assembly