interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / omc / tests / float / fma.om

124 lines · 2288 bytes Raw Blame History
1note fma: Wolfram rational oracle and ARM FPMulAdd semantics, see evidence/SEED-0/fma-exact-literals.
2note In particular, rounding the product before adding returns zero instead of -2^-46 / -2^-104.
3global cnt ulong 1
4global vals f64 1
5fn tick v f64 to f64
6put cnt 0 add get cnt 0 1
7ret v
8end
9fn fused a f64 b f64 c f64 to f64
10ret fma a b c
11end
12fn fused32 a f32 b f32 c f32 to f32
13ret fma a b c
14end
15fn check64 to int
16a = bitcast f64 ulong 4607182418800017409
17b = bitcast f64 ulong 4607182418800017406
18r = fma a b -1.0f64
19if ne bitcast ulong r 13362180094408261632
20ret 1
21end
22if ne bitcast ulong add mul a b -1.0f64 0
23ret 2
24end
25if ne bitcast ulong fused a b -1.0f64 13362180094408261632
26ret 3
27end
28m = bitcast f64 ulong 9218868437227405311
29if ne bitcast ulong fma m 2.0f64 neg m 9218868437227405311
30ret 4
31end
32s = bitcast f64 ulong 1
33if ne bitcast ulong fma s 0.5f64 s 2
34ret 5
35end
36ret 0
37end
38fn check32 to int
39a = bitcast f32 uint 1065353217
40b = bitcast f32 uint 1065353214
41r = fma a b -1.0f32
42if ne bitcast uint r 2826960896
43ret 6
44end
45if ne bitcast uint add mul a b -1.0f32 0
46ret 7
47end
48if ne bitcast uint fused32 a b -1.0f32 2826960896
49ret 8
50end
51m = bitcast f32 uint 2139095039
52if ne bitcast uint fma m 2.0f32 neg m 2139095039
53ret 9
54end
55s = bitcast f32 uint 1
56if ne bitcast uint fma s 0.5f32 s 2
57ret 10
58end
59ret 0
60end
61fn special to int
62if ne bitcast ulong fma -0.0f64 2.0f64 -0.0f64 9223372036854775808
63ret 11
64end
65if ne bitcast uint fma -0.0f32 2.0f32 0.0f32 0
66ret 12
67end
68inf = div 1.0f64 0.0f64
69if ne fma inf 2.0f64 0.0f64 inf
70ret 13
71end
72n = fma 0.0f64 inf 1.0f64
73if eq n n
74ret 14
75end
76q = bitcast f64 ulong 9221120237041090626
77n = fma q 2.0f64 1.0f64
78if eq n n
79ret 15
80end
81s = bitcast f64 ulong 9218868437227405313
82n = fma 1.0f64 s 0.0f64
83if eq n n
84ret 16
85end
86if eq and bitcast ulong n 2251799813685248 0
87ret 17
88end
89n = fma 1.0f64 2.0f64 q
90if eq n n
91ret 18
92end
93ret 0
94end
95fn main to int
96r = check64
97if ne r 0
98ret r
99end
100r = check32
101if ne r 0
102ret r
103end
104r = special
105if ne r 0
106ret r
107end
108put vals 0 fma tick 2.0f64 tick 3.0f64 tick 7.0f64
109if ne get cnt 0 3
110ret 19
111end
112if ne get vals 0 13.0f64
113ret 20
114end
115v = fma 2.0f64 fma 1.0f64 2.0f64 1.0f64 7.0f64
116v = fma v 2.0f64 -1.0f64
117if ne v 25.0f64
118ret 21
119end
120if ne fma fma 1.0f32 2.0f32 3.0f32 4.0f32 fma 1.0f32 2.0f32 3.0f32 25.0f32
121ret 22
122end
123ret 0
124end