Subversion Repositories Kolibri OS

Rev

Rev 4872 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/* wf_scalb.c -- float version of w_scalb.c.
2
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3
 */
4
 
5
/*
6
 * ====================================================
7
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8
 *
9
 * Developed at SunPro, a Sun Microsystems, Inc. business.
10
 * Permission to use, copy, modify, and distribute this
11
 * software is freely granted, provided that this notice
12
 * is preserved.
13
 * ====================================================
14
 */
15
 
16
/*
17
 * wrapper scalbf(float x, float fn) is provide for
18
 * passing various standard test suite. One
19
 * should use scalbn() instead.
20
 */
21
 
22
#include "fdlibm.h"
23
#include 
24
 
25
#ifdef __STDC__
26
#ifdef _SCALB_INT
27
	float scalbf(float x, int fn)		/* wrapper scalbf */
28
#else
29
	float scalbf(float x, float fn)		/* wrapper scalbf */
30
#endif
31
#else
32
	float scalbf(x,fn)			/* wrapper scalbf */
33
#ifdef _SCALB_INT
34
	float x; int fn;
35
#else
36
	float x,fn;
37
#endif
38
#endif
39
{
40
#ifdef _IEEE_LIBM
41
	return __ieee754_scalbf(x,fn);
42
#else
43
	float 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_scalbf(x,fn);
52
	if(_LIB_VERSION == _IEEE_) return z;
53
	if(!(finitef(z)||isnan(z))&&finitef(x)) {
54
	    /* scalbf overflow; SVID also returns +-HUGE_VAL */
55
	    exc.type = OVERFLOW;
56
	    exc.name = "scalbf";
57
	    exc.err = 0;
58
	    exc.arg1 = (double)x;
59
	    exc.arg2 = (double)fn;
60
	    exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL;
61
	    if (_LIB_VERSION == _POSIX_)
62
	       errno = ERANGE;
63
	    else if (!matherr(&exc)) {
64
	       errno = ERANGE;
65
	    }
66
	    if (exc.err != 0)
67
	       errno = exc.err;
68
            return exc.retval;
69
	}
70
	if(z==(float)0.0&&z!=x) {
71
	    /* scalbf underflow */
72
	    exc.type = UNDERFLOW;
73
	    exc.name = "scalbf";
74
	    exc.err = 0;
75
	    exc.arg1 = (double)x;
76
	    exc.arg2 = (double)fn;
77
	    exc.retval = copysign(0.0,x);
78
	    if (_LIB_VERSION == _POSIX_)
79
	       errno = ERANGE;
80
	    else if (!matherr(&exc)) {
81
	       errno = ERANGE;
82
	    }
83
	    if (exc.err != 0)
84
	       errno = exc.err;
85
            return exc.retval;
86
	}
87
#ifndef _SCALB_INT
88
	if(!finitef(fn)) errno = ERANGE;
89
#endif
90
	return z;
91
#endif
92
}
93
 
94
#ifdef _DOUBLE_IS_32BITS
95
 
96
#ifdef __STDC__
97
#ifdef _SCALB_INT
98
	double scalb(double x, int fn)
99
#else
100
	double scalb(double x, double fn)
101
#endif
102
#else
103
	double scalb(x, fn)
104
#ifdef _SCALB_INT
105
	double x; int fn;
106
#else
107
	double x,fn;
108
#endif
109
#endif
110
{
111
#ifdef _SCALB_INT
112
	return (double) scalbf((float) x, fn);
113
#else
114
	return (double) scalbf((float) x, (float) fn);
115
#endif
116
}
117
 
118
#endif /* defined(_DOUBLE_IS_32BITS) */