OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [newlib/] [newlib/] [newlib/] [libm/] [math/] [w_scalb.c] - Blame information for rev 39

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
 
2
/* @(#)w_scalb.c 5.1 93/09/24 */
3
/*
4
 * ====================================================
5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6
 *
7
 * Developed at SunPro, a Sun Microsystems, Inc. business.
8
 * Permission to use, copy, modify, and distribute this
9
 * software is freely granted, provided that this notice
10
 * is preserved.
11
 * ====================================================
12
 */
13
 
14
/*
15
 * wrapper scalb(double x, double fn) is provide for
16
 * passing various standard test suite. One
17
 * should use scalbn() instead.
18
 */
19
 
20
#include "fdlibm.h"
21
#include <errno.h>
22
 
23
#ifndef _DOUBLE_IS_32BITS
24
 
25
#ifdef __STDC__
26
#ifdef _SCALB_INT
27
        double scalb(double x, int fn)          /* wrapper scalb */
28
#else
29
        double scalb(double x, double fn)       /* wrapper scalb */
30
#endif
31
#else
32
        double scalb(x,fn)                      /* wrapper scalb */
33
#ifdef _SCALB_INT
34
        double x; int fn;
35
#else
36
        double x,fn;
37
#endif
38
#endif
39
{
40
#ifdef _IEEE_LIBM
41
        return __ieee754_scalb(x,fn);
42
#else
43
        double z;
44
#ifndef HUGE_VAL 
45
#define HUGE_VAL inf
46
        double inf = 0.0;
47
 
48
        SET_HIGH_WORD(inf,0x7ff00000);  /* set inf to infinite */
49
#endif
50
        struct exception exc;
51
        z = __ieee754_scalb(x,fn);
52
        if(_LIB_VERSION == _IEEE_) return z;
53
        if(!(finite(z)||isnan(z))&&finite(x)) {
54
            /* scalb overflow; SVID also returns +-HUGE_VAL */
55
            exc.type = OVERFLOW;
56
            exc.name = "scalb";
57
            exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL;
58
            if (_LIB_VERSION == _POSIX_)
59
               errno = ERANGE;
60
            else if (!matherr(&exc)) {
61
               errno = ERANGE;
62
            }
63
            if (exc.err != 0)
64
               errno = exc.err;
65
            return exc.retval;
66
        }
67
        if(z==0.0&&z!=x) {
68
            /* scalb underflow */
69
            exc.type = UNDERFLOW;
70
            exc.name = "scalb";
71
            exc.retval = copysign(0.0,x);
72
            if (_LIB_VERSION == _POSIX_)
73
               errno = ERANGE;
74
            else if (!matherr(&exc)) {
75
               errno = ERANGE;
76
            }
77
            if (exc.err != 0)
78
               errno = exc.err;
79
            return exc.retval;
80
        }
81
#ifndef _SCALB_INT
82
        if(!finite(fn)) errno = ERANGE;
83
#endif
84
        return z;
85
#endif 
86
}
87
 
88
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.