~ubuntu-branches/ubuntu/lucid/9base/lucid

« back to all changes in this revision

Viewing changes to lib9/fmt/nan64.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-08-20 17:34:06 UTC
  • mfrom: (6.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090820173406-xpwqa9ruyevvc0ut
Tags: 1:3-3
* Updating maintainer field.
* Updating vcs fields.
* Updating package to standards version 3.8.3.
* Updatin variables writing in rules to consistent style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 */
7
7
 
8
8
#include "plan9.h"
 
9
#include <assert.h>
9
10
#include "fmt.h"
10
11
#include "fmtdef.h"
11
12
 
12
 
#if defined (__APPLE__) || (__powerpc__)
13
 
#define _NEEDLL
14
 
#endif
15
 
 
16
13
static uvlong uvnan    = ((uvlong)0x7FF00000<<32)|0x00000001;
17
14
static uvlong uvinf    = ((uvlong)0x7FF00000<<32)|0x00000000;
18
15
static uvlong uvneginf = ((uvlong)0xFFF00000<<32)|0x00000000;
19
16
 
 
17
/* gcc sees through the obvious casts. */
 
18
static uvlong
 
19
d2u(double d)
 
20
{
 
21
        union {
 
22
                uvlong v;
 
23
                double d;
 
24
        } u;
 
25
        assert(sizeof(u.d) == sizeof(u.v));
 
26
        u.d = d;
 
27
        return u.v;
 
28
}
 
29
 
 
30
static double
 
31
u2d(uvlong v)
 
32
{
 
33
        union {
 
34
                uvlong v;
 
35
                double d;
 
36
        } u;
 
37
        assert(sizeof(u.d) == sizeof(u.v));
 
38
        u.v = v;
 
39
        return u.d;
 
40
}
 
41
 
20
42
double
21
43
__NaN(void)
22
44
{
23
 
        uvlong *p;
24
 
 
25
 
        /* gcc complains about "return *(double*)&uvnan;" */
26
 
        p = &uvnan;
27
 
        return *(double*)p;
 
45
        return u2d(uvnan);
28
46
}
29
47
 
30
48
int
31
49
__isNaN(double d)
32
50
{
33
51
        uvlong x;
34
 
        double *p;
35
 
 
36
 
        p = &d;
37
 
        x = *(uvlong*)p;
38
 
        return (ulong)(x>>32)==0x7FF00000 && !__isInf(d, 0);
 
52
        
 
53
        x = d2u(d);
 
54
        /* IEEE 754: exponent bits 0x7FF and non-zero mantissa */
 
55
        return (x&uvinf) == uvinf && (x&~uvneginf) != 0;
39
56
}
40
57
 
41
58
double
42
59
__Inf(int sign)
43
60
{
44
 
        uvlong *p;
45
 
 
46
 
        if(sign < 0)
47
 
                p = &uvinf;
48
 
        else
49
 
                p = &uvneginf;
50
 
        return *(double*)p;
 
61
        return u2d(sign < 0 ? uvneginf : uvinf);
51
62
}
52
63
 
53
64
int
54
65
__isInf(double d, int sign)
55
66
{
56
67
        uvlong x;
57
 
        double *p;
58
 
 
59
 
        p = &d;
60
 
        x = *(uvlong*)p;
 
68
        
 
69
        x = d2u(d);
61
70
        if(sign == 0)
62
71
                return x==uvinf || x==uvneginf;
63
72
        else if(sign > 0)