| 1 | /* s_logbf.c -- float version of s_logb.c. |
| 2 | */ |
| 3 | |
| 4 | /* |
| 5 | * ==================================================== |
| 6 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 7 | * |
| 8 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
| 9 | * Permission to use, copy, modify, and distribute this |
| 10 | * software is freely granted, provided that this notice |
| 11 | * is preserved. |
| 12 | * ==================================================== |
| 13 | */ |
| 14 | |
| 15 | #include <math.h> |
| 16 | #include <math_private.h> |
| 17 | #include <libm-alias-float.h> |
| 18 | #include <fix-int-fp-convert-zero.h> |
| 19 | |
| 20 | float |
| 21 | __logbf (float x) |
| 22 | { |
| 23 | int32_t ix, rix; |
| 24 | |
| 25 | GET_FLOAT_WORD (ix, x); |
| 26 | ix &= 0x7fffffff; /* high |x| */ |
| 27 | if (ix == 0) |
| 28 | return (float) -1.0 / fabsf (x); |
| 29 | if (ix >= 0x7f800000) |
| 30 | return x * x; |
| 31 | if (__glibc_unlikely ((rix = ix >> 23) == 0)) |
| 32 | { |
| 33 | /* POSIX specifies that denormal number is treated as |
| 34 | though it were normalized. */ |
| 35 | rix -= __builtin_clz (ix) - 9; |
| 36 | } |
| 37 | if (FIX_INT_FP_CONVERT_ZERO && rix == 127) |
| 38 | return 0.0f; |
| 39 | return (float) (rix - 127); |
| 40 | } |
| 41 | libm_alias_float (__logb, logb) |
| 42 | |