The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
Elliott Hughes | 99ef447 | 2022-01-12 17:51:20 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2005-2020 Rich Felker, et al. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 3 | * |
Elliott Hughes | 99ef447 | 2022-01-12 17:51:20 -0800 | [diff] [blame^] | 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Please see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT |
| 7 | * for all contributors to musl. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 8 | */ |
Elliott Hughes | 99ef447 | 2022-01-12 17:51:20 -0800 | [diff] [blame^] | 9 | #include <math.h> |
| 10 | #include <stdint.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 11 | |
Elliott Hughes | 99ef447 | 2022-01-12 17:51:20 -0800 | [diff] [blame^] | 12 | float scalbnf(float x, int n) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 13 | { |
Elliott Hughes | 99ef447 | 2022-01-12 17:51:20 -0800 | [diff] [blame^] | 14 | union {float f; uint32_t i;} u; |
| 15 | float_t y = x; |
| 16 | |
| 17 | if (n > 127) { |
| 18 | y *= 0x1p127f; |
| 19 | n -= 127; |
| 20 | if (n > 127) { |
| 21 | y *= 0x1p127f; |
| 22 | n -= 127; |
| 23 | if (n > 127) |
| 24 | n = 127; |
| 25 | } |
| 26 | } else if (n < -126) { |
| 27 | y *= 0x1p-126f * 0x1p24f; |
| 28 | n += 126 - 24; |
| 29 | if (n < -126) { |
| 30 | y *= 0x1p-126f * 0x1p24f; |
| 31 | n += 126 - 24; |
| 32 | if (n < -126) |
| 33 | n = -126; |
| 34 | } |
Elliott Hughes | 8da8ca4 | 2018-05-08 13:35:33 -0700 | [diff] [blame] | 35 | } |
Elliott Hughes | 99ef447 | 2022-01-12 17:51:20 -0800 | [diff] [blame^] | 36 | u.i = (uint32_t)(0x7f+n)<<23; |
| 37 | x = y * u.f; |
| 38 | return x; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | __strong_reference(scalbnf, ldexpf); |