1
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
8
* returns the leading non-zero
16
for(i=Mpprec-1; i>=0; i--)
19
//print("sigfig %d %d\n", i-z+1, z);
24
* shifts the leading non-zero
25
* word of the number to Mpnorm
41
// this will normalize to the nearest word
43
s = (Mpnorm-os) * Mpscale;
45
// further normalize to the nearest bit
52
// this error comes from trying to
53
// convert an Inf or something
54
// where the initial x=0x80000000
55
s = (Mpnorm-os) * Mpscale;
60
mpshiftfix(&a->val, s);
64
/// implements float arihmetic
67
mpaddfltflt(Mpflt *a, Mpflt *b)
73
print("\n%F + %F", a, b);
87
// a is larger, shift b right
89
mpshiftfix(&c.val, -s);
90
mpaddfixfix(&a->val, &c.val);
94
// b is larger, shift a right
95
mpshiftfix(&a->val, s);
97
mpaddfixfix(&a->val, &b->val);
100
mpaddfixfix(&a->val, &b->val);
105
print(" = %F\n\n", a);
109
mpmulfltflt(Mpflt *a, Mpflt *b)
114
print("%F\n * %F\n", a, b);
131
mpmulfract(&a->val, &b->val);
132
a->exp = (a->exp + b->exp) + Mpscale*Mpprec - Mpscale - 1;
136
print(" = %F\n\n", a);
140
mpdivfltflt(Mpflt *a, Mpflt *b)
146
print("%F\n / %F\n", a, b);
154
yyerror("mpdivfltflt divide by zero");
168
mpshiftfix(&c.val, Mpscale);
171
mpdivfract(&a->val, &c.val);
172
a->exp = (a->exp-c.exp) - Mpscale*(Mpprec-1) + 1;
176
print(" = %F\n\n", a);
187
yyerror("mpgetflt ovf");
194
yyerror("mpgetflt norm");
198
while((a->val.a[Mpnorm-1] & Mpsign) == 0) {
199
mpshiftfix(&a->val, 1);
203
// the magic numbers (64, 63, 53, 10, -1074) are
204
// IEEE specific. this should be done machine
205
// independently or in the 6g half of the compiler
207
// pick up the mantissa and a rounding bit in a uvlong
210
for(i=Mpnorm-1; s>=Mpscale; i--) {
211
v = (v<<Mpscale) | a->val.a[i];
216
vm = (vm<<s) | (a->val.a[i]>>(Mpscale-s));
218
// continue with 64 more bits
220
for(; s>=Mpscale; i--) {
221
v = (v<<Mpscale) | a->val.a[i];
225
v = (v<<s) | (a->val.a[i]>>(Mpscale-s));
228
e = Mpnorm*Mpscale + a->exp - 53;
233
v |= vm & ((1ULL<<s) - 1);
238
//print("vm=%.16llux v=%.16llux\n", vm, v);
240
if(v != 0 || (vm&2ULL) != 0)
241
vm = (vm>>1) + (vm&1ULL);
254
mpmovecflt(Mpflt *a, double c)
261
print("\nconst %g", c);
262
mpmovecfix(&a->val, 0);
274
for(i=0; i<10; i++) {
282
mpshiftfix(&a->val, Mpscale);