在 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.

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.


> +    }
>      return log(x) / 0.69314718246459960938;
>  }
>  
>  float log2f(float x)
>  {
> +    ieee754_float u = { .f = x };
> +    if (u.sgn == 0 && u.f23 == 0 && u.exp > 0 && u.exp < 0xff) {
> +        // Handle exact powers of two exactly
> +        return u.exp - 127;
> +    }
>      return logf(x) / 0.69314718246459960938f;
>  }
>  
> 


-- 
Best regards,
LH_Mouse

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to