blob: bc0f08e9953a4c7ba91824d57c63356e249002a0 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 */
11
12#include "math.h"
13#include "math_private.h"
14#include <errno.h>
15
16/* TODO: POSIX says:
17 *
18 * "If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
19 * then errno shall be set to [ERANGE]. If the integer expression
20 * (math_errhandling & MATH_ERREXCEPT) is non-zero, then the underflow
21 * floating-point exception shall be raised."
22 *
23 * *And it says the same about scalbn*! Thus these two functions
24 * are the same and can be just aliased.
25 *
26 * Currently, ldexp tries to be vaguely POSIX compliant while scalbn
27 * does not (it does not set ERRNO).
28 */
29
30double ldexp(double value, int _exp)
31{
32 if (!isfinite(value) || value == 0.0)
33 return value;
34 value = scalbn(value, _exp);
35 if (!isfinite(value) || value == 0.0)
36 errno = ERANGE;
37 return value;
38}
39libm_hidden_def(ldexp)