Re: float exponent
- From: Eugene.Styer@xxxxxxx
- Date: Wed, 31 Oct 2007 11:45:32 -0700
On Oct 31, 1:42 am, "cr88192" <cr88...@xxxxxxxxxxxxxxxxxx> wrote:
just wondering:
anyone here know how to go about computing floating point exponents (like in
'pow')?...
sadly, this one escapes me, and I can't find more info.
f2xm1 and fyl2x would almost seem to provide something, but f2xm1 only works
over a very small range.
attempting to disassemble pow has not turned out well, as I think it goes
off in some dll somewhere, and each place I look seems to jump somewhere
else.
ok, maybe I could rig up an interactive disassembler if I really needed it,
but maybe someone here might know...
even more useful:
if whoever knows, also knows about a form for complexes.
and, if I am really lucky, for quaternions.
all this is for my compiler, for which I have now added an exponent
operator. sadly, at present, since I have not figured this out, I have ended
up having to deal with the float case by generating calls to pow and cpow.
as for the quaternion exponent (if I can find info on such a beast), is
almost gueranteed to be implemented as a hidden function call though.
well, at least the integer case went well:
x^y in my compiler is written as x`y.
x`y (2 values) is implemented as a small loop, and has a cost of O(y).
if y is a literal, however, small cases are special, and in the general case
it takes about O(log2 y), or, more correctly:
O(log2 y + y mod 2^(log2 y)).
potentially, similar could be used for certain constant/integer floating
point exponents (such as 1/2, 0, 1, and other integers). as such, secretly
calling 'pow' as the fallback case.
all this should work pretty well though, as most of the time, exponents are
probably going to look something like:
'x`2' or 'x`3', which can luckily be nicely handled with good old
multiplies...
or something...
The key part for calculating 2^x is to split x into integer (call this
xi) and fractional (call this xf) parts.
Then we know that 2^x = 2^(xi+xf) = 2^xi * 2^xf.
f2xm1 is fairly close to what you need for 2^xf, and fscale takes care
of most of the rest.
For complex numbers, I don't remember the exact formulas, but I
remember them involving sin/cos/pow, so I would recommend searching
for how to handle complex numbers in general, then map them to the
functions/code fragments you already have.
I know basically nothing about quaternions, but again I would
recommend searching for the generic formulas, and I suspect they too
will map to common functions.
.
- References:
- float exponent
- From: cr88192
- float exponent
- Prev by Date: Re: float exponent
- Next by Date: Re: float exponent
- Previous by thread: Re: float exponent
- Next by thread: Re: float exponent
- Index(es):
Relevant Pages
|