blob: 8cf1e01150da269b07b5ff3918dbe3cd02bfde2e [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
Elliott Hughes99ef4472022-01-12 17:51:20 -08002 * Copyright (c) 2005-2020 Rich Felker, et al.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003 *
Elliott Hughes99ef4472022-01-12 17:51:20 -08004 * 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 Project1dc9e472009-03-03 19:28:35 -08008 */
Elliott Hughes99ef4472022-01-12 17:51:20 -08009#include <math.h>
10#include <stdint.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080011
Elliott Hughes99ef4472022-01-12 17:51:20 -080012float scalbnf(float x, int n)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080013{
Elliott Hughes99ef4472022-01-12 17:51:20 -080014 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 Hughes8da8ca42018-05-08 13:35:33 -070035 }
Elliott Hughes99ef4472022-01-12 17:51:20 -080036 u.i = (uint32_t)(0x7f+n)<<23;
37 x = y * u.f;
38 return x;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039}
40
41__strong_reference(scalbnf, ldexpf);