source: soft/giet_vm/giet_libs/math/s_scalbn.c @ 812

Last change on this file since 812 was 581, checked in by laurent, 9 years ago

Adding ocean application, some mathematics functions and distributed locks

File size: 1.8 KB
Line 
1/*
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/* Modified for GIET-VM static OS at UPMC, France 2015.
13 */
14
15/*
16 * scalbln(double x, long n)
17 * scalbln(x,n) returns x * 2**n computed by exponent
18 * manipulation rather than by actually performing an
19 * exponentiation or a multiplication.
20 */
21
22#include "../math.h"
23#include "math_private.h"
24#include <limits.h>
25
26static const double
27two54  = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
28twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
29huge   = 1.0e+300,
30tiny   = 1.0e-300;
31
32double scalbln(double x, long n)
33{
34        int32_t k, hx, lx;
35
36        EXTRACT_WORDS(hx, lx, x);
37        k = (hx & 0x7ff00000) >> 20; /* extract exponent */
38        if (k == 0) { /* 0 or subnormal x */
39                if ((lx | (hx & 0x7fffffff)) == 0)
40                        return x; /* +-0 */
41                x *= two54;
42                GET_HIGH_WORD(hx, x);
43                k = ((hx & 0x7ff00000) >> 20) - 54;
44        }
45        if (k == 0x7ff)
46                return x + x; /* NaN or Inf */
47        k = k + n;
48        if (k > 0x7fe)
49                return huge * copysign(huge, x); /* overflow */
50        if (n < -50000)
51                return tiny * copysign(tiny, x); /* underflow */
52        if (k > 0) { /* normal result */
53                SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));
54                return x;
55        }
56        if (k <= -54) {
57                if (n > 50000) /* in case integer overflow in n+k */
58                        return huge * copysign(huge, x); /* overflow */
59                return tiny * copysign(tiny, x); /* underflow */
60        }
61        k += 54; /* subnormal result */
62        SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));
63        return x * twom54;
64}
65
66double scalbn(double x, int n)
67{
68        return scalbln(x, n);
69}
70
Note: See TracBrowser for help on using the repository browser.