summaryrefslogtreecommitdiff
path: root/userland/libc/math/ldexp.c
blob: 06d4cd0860d5b256bc8f7c4dd16624e25d3175aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <float.h>
#include <math.h>

double ldexp(double x, int exp) {
  double sign = (x < 0.0) ? (-1) : (1);

  if (exp > 29) {
    return sign * HUGE_VAL;
  }
  double two_exp = 2 << exp;

  if (x > DBL_MAX / two_exp) {
    return sign * HUGE_VAL;
  }
  return x * two_exp;
}