-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpi.h
71 lines (62 loc) · 1.87 KB
/
fpi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef nil
#include <u.h>
#endif
typedef long Word;
typedef long long Vlong;
typedef unsigned long Single;
/* use u.h's FPdbleword */
#define Double FPdbleword
#define h hi
#define l lo
enum {
FractBits = 28,
CarryBit = 0x10000000,
HiddenBit = 0x08000000,
MsBit = HiddenBit,
NGuardBits = 3,
GuardMask = 0x07,
LsBit = (1<<NGuardBits),
SingleExpBias = 127,
SingleExpMax = 255,
DoubleExpBias = 1023,
DoubleExpMax = 2047,
ExpBias = DoubleExpBias,
ExpInfinity = DoubleExpMax,
};
typedef struct {
/* order matters: must start with s, e, l, h in that order */
unsigned char s;
short e;
/* double bits */
long l; /* 0000FFFFFFFFFFFFFFFFFFFFFFFFFGGG */
long h; /* 0000HFFFFFFFFFFFFFFFFFFFFFFFFFFF */
} Internal;
#define IsWeird(n) ((n)->e >= ExpInfinity)
#define IsInfinity(n) (IsWeird(n) && (n)->h == HiddenBit && (n)->l == 0)
#define SetInfinity(n) ((n)->e = ExpInfinity, (n)->h = HiddenBit, (n)->l = 0)
#define IsNaN(n) (IsWeird(n) && (((n)->h & ~HiddenBit) || (n)->l))
#define SetQNaN(n) ((n)->s = 0, (n)->e = ExpInfinity, \
(n)->h = HiddenBit|(LsBit<<1), (n)->l = 0)
#define IsZero(n) ((n)->e == 1 && (n)->h == 0 && (n)->l == 0)
#define SetZero(n) ((n)->e = 1, (n)->h = 0, (n)->l = 0)
/*
* fpi.c
*/
extern void fpiround(Internal *);
extern void fpiadd(Internal *, Internal *, Internal *);
extern void fpisub(Internal *, Internal *, Internal *);
extern void fpimul(Internal *, Internal *, Internal *);
extern void fpidiv(Internal *, Internal *, Internal *);
extern int fpicmp(Internal *, Internal *);
extern void fpinormalise(Internal*);
/*
* fpimem.c
*/
extern void fpis2i(Internal *, void *);
extern void fpid2i(Internal *, void *);
extern void fpiw2i(Internal *, void *);
extern void fpiv2i(Internal *, void *);
extern void fpii2s(void *, Internal *);
extern void fpii2d(void *, Internal *);
extern void fpii2w(Word *, Internal *);
extern void fpii2v(Vlong *, Internal *);