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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [linux/] [uClibc/] [libm/] [powerpc/] [w_scalb.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/***********************************************************************
2
**      File:    scalb.c
3
**
4
**      Contains: C source code for implementations of floating-point
5
**                scalb functions defined in header <fp.h>.  In
6
**                particular, this file contains implementations of
7
**                functions scalb and scalbl for double and long double
8
**                formats on PowerPC platforms.
9
**
10
**      Written by: Jon Okada, SANEitation Engineer, ext. 4-4838
11
**
12
**      Copyright: © 1992 by Apple Computer, Inc., all rights reserved
13
**
14
**      Change History ( most recent first ):
15
**
16
**      28 May 97  ali   made an speed improvement for large n,
17
**                       removed scalbl.
18
**      12 Dec 92  JPO   First created.
19
**
20
***********************************************************************/
21
 
22
typedef union
23
      {
24
      struct {
25
#if defined(__BIG_ENDIAN__)
26
        unsigned long int hi;
27
        unsigned long int lo;
28
#else
29
        unsigned long int lo;
30
        unsigned long int hi;
31
#endif
32
      } words;
33
      double dbl;
34
      } DblInHex;
35
 
36
static const double twoTo1023  = 8.988465674311579539e307;   // 0x1p1023
37
static const double twoToM1022 = 2.225073858507201383e-308;  // 0x1p-1022
38
 
39
 
40
/***********************************************************************
41
      double  scalb( double  x, long int n ) returns its argument x scaled
42
      by the factor 2^m.  NaNs, signed zeros, and infinities are propagated
43
      by this function regardless of the value of n.
44
 
45
      Exceptions:  OVERFLOW/INEXACT or UNDERFLOW inexact may occur;
46
                         INVALID for signaling NaN inputs ( quiet NaN returned ).
47
 
48
      Calls:  none.
49
***********************************************************************/
50
 
51
double scalb ( double x, int n  )
52
      {
53
      DblInHex xInHex;
54
 
55
      xInHex.words.lo = 0UL;                     // init. low half of xInHex
56
 
57
      if ( n > 1023 )
58
            {                                   // large positive scaling
59
            if ( n > 2097 )                     // huge scaling
60
                return ( ( x * twoTo1023 ) * twoTo1023 ) * twoTo1023;
61
            while ( n > 1023 )
62
                  {                             // scale reduction loop
63
                  x *= twoTo1023;               // scale x by 2^1023
64
                  n -= 1023;                    // reduce n by 1023
65
                  }
66
            }
67
 
68
      else if ( n < -1022 )
69
            {                                   // large negative scaling
70
            if ( n < -2098 )                    // huge negative scaling
71
                return ( ( x * twoToM1022 ) * twoToM1022 ) * twoToM1022;
72
            while ( n < -1022 )
73
                  {                             // scale reduction loop
74
                  x *= twoToM1022;              // scale x by 2^( -1022 )
75
                  n += 1022;                    // incr n by 1022
76
                  }
77
            }
78
 
79
/*******************************************************************************
80
*      -1022 <= n <= 1023; convert n to double scale factor.                   *
81
*******************************************************************************/
82
 
83
      xInHex.words.hi = ( ( unsigned long ) ( n + 1023 ) ) << 20;
84
      return ( x * xInHex.dbl );
85
      }

powered by: WebSVN 2.1.0

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