maybefloat.anubis
2.98 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
*Project* The Anubis Project
*Title* Using 'Maybe(Float)' numbers.
*Copyright* Copyright (c) Alain Prouté 2001.
*Author* Alain Prouté
*Overview*
Data of the primitive type 'Float' represent only actual numbers, not infinity or other
things as in the usual definitions of floating point numbers (IEEE 754). Nevertheless,
since floating point operations may fail (division, tangent, etc... and even sum, which
may still overflow), about no operation on floating point numbers yields a floating
point number. This is why the Anubis virtual machine constructs in general data of type
Maybe(Float) as the result of a computation. See 'predef.anubis' for the details of
this, operation by operation.
However, I'm not sure I will not accept the whole IEEE 754 standard for Anubis version
2, because, the effect of my politics in version 1 is just that we use Maybe(Float) in
most cases instead of Float. This is not a real advantage, and also makes the
computations slower. Hence, probably, Anubis version 2 will implement IEEE 754 as is.
For the time being, here are some operations 'translated' for 'Maybe(Float)'.
public define Maybe(Float)
Maybe(Float) x + Maybe(Float) y =
if x succeeds as x1 then
if y succeeds as y1 then
x1 + y1.
public define Maybe(Float)
Maybe(Float) x * Maybe(Float) y =
if x succeeds as x1 then
if y succeeds as y1 then
x1 * y1.
public define Maybe(Float)
Maybe(Float) x / Maybe(Float) y =
if x succeeds as x1 then
if y succeeds as y1 then
x1 / y1.
public define Maybe(Float)
Maybe(Float) x - Maybe(Float) y =
if x succeeds as x1 then
if y succeeds as y1 then
x1 - y1.
public define Maybe(Float)
Maybe(Float) x ^ Maybe(Float) y =
if x succeeds as x1 then
if y succeeds as y1 then
x1 ^ y1.
public define Maybe(Bool)
Maybe(Float) x < Maybe(Float) y =
if x succeeds as x1 then
if y succeeds as y1 then
success(x1 < y1).
public define Bool
Maybe(Float) x < Maybe(Float) y =
if (Maybe(Bool))(x < y) is
{
failure then false,
success(b) then b
}.
public define Maybe(Bool)
Maybe(Float) x =< Maybe(Float) y =
if x succeeds as x1 then
if y succeeds as y1 then
success(x1 =< y1).
public define Maybe(Float)
opp(Maybe(Float) x) =
if x succeeds as x1 then 0 - x1.
public define Maybe(Float)
- Maybe(Float) x =
if x succeeds as x1 then 0 - x1.
public define Maybe(Float)
abs(Maybe(Float) x) =
if x < success(0.0) then opp(x) else x.
public define Maybe(Float)
sqrt
(
Maybe(Float) x
) =
if x is
{
failure then failure,
success(f) then sqrt(f)
}.
public define Maybe(Float)
sin
(
Maybe(Float) x
) =
if x is
{
failure then failure,
success(f) then success(sin(f))
}.