On Fri, 13 Nov 2020, Liu Hao wrote:
在 2020/11/13 下午5:04, Martin Storsjö 写道:
These routines are used on msvcrt.dll on arm, which only provides
log(). For exact powers of two, produce an exact result instead
of one that only is numerically close.
Defer to the normal implementation for anything other than the
simple cases (negative values, denormals, infinities, etc).
Signed-off-by: Martin Storsjö <[email protected]>
---
mingw-w64-crt/math/arm-common/log2.c | 29 ++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
+ // Handle exact powers of two exactly
+ return u.exp - 1023;
The value might be negative, so you have to cast `u.exp` to `int` before
subtraction.
Thanks, good catch. Weirdly enough, it did end up returning the right
value in practice even for those cases - maybe it's some of the subtleties
of implicit value conversion at play, but an explicit cast clearly makes
it clearer.
Side note: There is an additional consideration in case of x86. There is
no hardware instruction that performs conversion between `uint64_t` and
`double`, so if the value can't be negative, it is preferable to perform
a cast to `int64_t` in between. ARM probably has hardware conversion
instructions between them so it's not an issue there.
Hm, right, not sure if there's things there that handle the full unsigned
range either. But it doesn't really matter as only the range of -1022 to
1023 is used here.
// Martin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public