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

Subversion Repositories or1k_old

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/*******************************************************************************
2
*                                                                              *
3
*      File frexpldexp.c,                                                      *
4
*      Functions frexp(x) and ldexp(x),                                        *
5
*      Implementation of frexp and ldexp functions for the PowerPC.            *
6
*                                                                              *
7
*      Copyright © 1991 Apple Computer, Inc.  All rights reserved.             *
8
*                                                                              *
9
*      Written by Ali Sazegari, started on January 1991,                       *
10
*                                                                              *
11
*      W A R N I N G:  This routine expects a 64 bit double model.             *
12
*                                                                              *
13
*      December03 1992: first rs6000 implementation.                           *
14
*      October 05 1993: added special cases for NaN and ° in frexp.            *
15
*      May     27 1997: improved the performance of frexp by eliminating the   *
16
*                       switch statement.                                      *
17
*        June      13 2001: (ram) rewrote frexp to eliminate calls to scalb and    *
18
*                               logb.                                                                    *
19
*                                                                              *
20
*******************************************************************************/
21
 
22
#include <limits.h>
23
#include <math.h>
24
 
25
static const double two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
26
 
27
typedef union
28
      {
29
      struct {
30
#if defined(__BIG_ENDIAN__)
31
        unsigned long int hi;
32
        unsigned long int lo;
33
#else
34
        unsigned long int lo;
35
        unsigned long int hi;
36
#endif
37
      } words;
38
      double dbl;
39
      } DblInHex;
40
 
41
double frexp ( double value, int *eptr )
42
      {
43
      DblInHex argument;
44
      unsigned long int valueHead;
45
 
46
      argument.dbl = value;
47
      valueHead = argument.words.hi & 0x7fffffffUL; // valueHead <- |x|
48
 
49
      *eptr = 0;
50
        if ( valueHead >= 0x7ff00000 || ( valueHead | argument.words.lo ) == 0 )
51
                return value;           // 0, inf, or NaN
52
 
53
        if ( valueHead < 0x00100000 )
54
                {       // denorm
55
                argument.dbl = two54 * value;
56
                valueHead = argument.words.hi &0x7fffffff;
57
                *eptr = -54;
58
                }
59
        *eptr += ( valueHead >> 20 ) - 1022;
60
        argument.words.hi = ( argument.words.hi & 0x800fffff ) | 0x3fe00000;
61
        return argument.dbl;
62
        }
63
 

powered by: WebSVN 2.1.0

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