-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathieee_float.cpp
1334 lines (1107 loc) · 26 KB
/
ieee_float.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************\
Module:
Author: Daniel Kroening, kroening@kroening.com
\*******************************************************************/
#include "ieee_float.h"
#include "arith_tools.h"
#include "bitvector_types.h"
#include "floatbv_expr.h"
#include "invariant.h"
#include "std_expr.h"
#include <cstdint>
#include <limits>
mp_integer ieee_float_spect::bias() const
{
return power(2, e-1)-1;
}
floatbv_typet ieee_float_spect::to_type() const
{
floatbv_typet result;
result.set_f(f);
result.set_width(width());
if(x86_extended)
result.set(ID_x86_extended, true);
return result;
}
mp_integer ieee_float_spect::max_exponent() const
{
return power(2, e)-1;
}
mp_integer ieee_float_spect::max_fraction() const
{
return power(2, f)-1;
}
void ieee_float_spect::from_type(const floatbv_typet &type)
{
std::size_t width=type.get_width();
f=type.get_f();
DATA_INVARIANT(f != 0, "mantissa must be at least 1 bit");
DATA_INVARIANT(
f < width,
"mantissa bits must be less than "
"originating type width");
e=width-f-1;
x86_extended=type.get_bool(ID_x86_extended);
if(x86_extended)
e=e-1; // no hidden bit
}
void ieee_float_valuet::print(std::ostream &out) const
{
out << to_ansi_c_string();
}
std::string ieee_float_valuet::format(const format_spect &format_spec) const
{
std::string result;
switch(format_spec.style)
{
case format_spect::stylet::DECIMAL:
result+=to_string_decimal(format_spec.precision);
break;
case format_spect::stylet::SCIENTIFIC:
result+=to_string_scientific(format_spec.precision);
break;
case format_spect::stylet::AUTOMATIC:
{
// On Linux, the man page says:
// "Style e is used if the exponent from its conversion
// is less than -4 or greater than or equal to the precision."
//
// On BSD, it's
// "The argument is printed in style f (F) or in style e (E)
// whichever gives full precision in minimum space."
mp_integer _exponent, _fraction;
extract_base10(_fraction, _exponent);
mp_integer adjusted_exponent=base10_digits(_fraction)+_exponent;
if(adjusted_exponent>=format_spec.precision ||
adjusted_exponent<-4)
{
result+=to_string_scientific(format_spec.precision);
}
else
{
result+=to_string_decimal(format_spec.precision);
// Implementations tested also appear to suppress trailing zeros
// and trailing dots.
{
std::size_t trunc_pos=result.find_last_not_of('0');
if(trunc_pos!=std::string::npos)
result.resize(trunc_pos+1);
}
if(!result.empty() && result.back()=='.')
result.resize(result.size()-1);
}
}
break;
}
while(result.size()<format_spec.min_width)
result=" "+result;
return result;
}
mp_integer ieee_float_valuet::base10_digits(const mp_integer &src)
{
PRECONDITION(src >= 0);
mp_integer tmp=src;
mp_integer result=0;
while(tmp!=0) { ++result; tmp/=10; }
return result;
}
std::string ieee_float_valuet::to_string_decimal(std::size_t precision) const
{
std::string result;
if(sign_flag)
result+='-';
if((NaN_flag || infinity_flag) && !sign_flag)
result+='+';
// special cases
if(NaN_flag)
result+="NaN";
else if(infinity_flag)
result+="inf";
else if(is_zero())
{
result+='0';
// add zeros, if needed
if(precision>0)
{
result+='.';
for(std::size_t i=0; i<precision; i++)
result+='0';
}
}
else
{
mp_integer _exponent, _fraction;
extract_base2(_fraction, _exponent);
// convert to base 10
if(_exponent>=0)
{
result+=integer2string(_fraction*power(2, _exponent));
// add dot and zeros, if needed
if(precision>0)
{
result+='.';
for(std::size_t i=0; i<precision; i++)
result+='0';
}
}
else
{
#if 1
mp_integer position=-_exponent;
// 10/2=5 -- this makes it base 10
_fraction*=power(5, position);
// apply rounding
if(position>precision)
{
mp_integer r=power(10, position-precision);
mp_integer remainder=_fraction%r;
_fraction/=r;
// not sure if this is the right kind of rounding here
if(remainder>=r/2)
++_fraction;
position=precision;
}
std::string tmp=integer2string(_fraction);
// pad with zeros from the front, if needed
while(mp_integer(tmp.size())<=position) tmp="0"+tmp;
const std::size_t dot =
tmp.size() - numeric_cast_v<std::size_t>(position);
result+=std::string(tmp, 0, dot)+'.';
result+=std::string(tmp, dot, std::string::npos);
// append zeros if needed
for(mp_integer i=position; i<precision; ++i)
result+='0';
#else
result+=integer2string(_fraction);
if(_exponent!=0)
result+="*2^"+integer2string(_exponent);
#endif
}
}
return result;
}
/// format as [-]d.ddde+-d Note that printf always produces at least two digits
/// for the exponent.
std::string ieee_float_valuet::to_string_scientific(std::size_t precision) const
{
std::string result;
if(sign_flag)
result+='-';
if((NaN_flag || infinity_flag) && !sign_flag)
result+='+';
// special cases
if(NaN_flag)
result+="NaN";
else if(infinity_flag)
result+="inf";
else if(is_zero())
{
result+='0';
// add zeros, if needed
if(precision>0)
{
result+='.';
for(std::size_t i=0; i<precision; i++)
result+='0';
}
result+="e0";
}
else
{
mp_integer _exponent, _fraction;
extract_base10(_fraction, _exponent);
// C99 appears to say that conversion to decimal should
// use the currently selected IEEE rounding mode.
if(base10_digits(_fraction)>precision+1)
{
// re-align
mp_integer distance=base10_digits(_fraction)-(precision+1);
mp_integer p=power(10, distance);
mp_integer remainder=_fraction%p;
_fraction/=p;
_exponent+=distance;
if(remainder==p/2)
{
// need to do rounding mode here
++_fraction;
}
else if(remainder>p/2)
++_fraction;
}
std::string decimals=integer2string(_fraction);
CHECK_RETURN(!decimals.empty());
// First add top digit to result.
result+=decimals[0];
// Now add dot and further zeros, if needed.
if(precision>0)
{
result+='.';
while(decimals.size()<precision+1)
decimals+='0';
result+=decimals.substr(1, precision);
}
// add exponent
result+='e';
std::string exponent_str=
integer2string(base10_digits(_fraction)+_exponent-1);
if(!exponent_str.empty() && exponent_str[0]!='-')
result+='+';
result+=exponent_str;
}
return result;
}
void ieee_float_valuet::unpack(const mp_integer &i)
{
PRECONDITION(spec.f != 0);
PRECONDITION(spec.e != 0);
{
mp_integer tmp=i;
// split this apart
mp_integer pf=power(2, spec.f);
fraction=tmp%pf;
tmp/=pf;
mp_integer pe=power(2, spec.e);
exponent=tmp%pe;
tmp/=pe;
sign_flag=(tmp!=0);
}
// NaN?
if(exponent==spec.max_exponent() && fraction!=0)
{
make_NaN();
}
else if(exponent==spec.max_exponent() && fraction==0) // Infinity
{
NaN_flag=false;
infinity_flag=true;
}
else if(exponent==0 && fraction==0) // zero
{
NaN_flag=false;
infinity_flag=false;
}
else if(exponent==0) // denormal?
{
NaN_flag=false;
infinity_flag=false;
exponent=-spec.bias()+1; // NOT -spec.bias()!
}
else // normal
{
NaN_flag=false;
infinity_flag=false;
fraction+=power(2, spec.f); // hidden bit!
exponent-=spec.bias(); // un-bias
}
}
bool ieee_float_valuet::is_normal() const
{
return fraction>=power(2, spec.f);
}
mp_integer ieee_float_valuet::pack() const
{
mp_integer result=0;
// sign bit
if(sign_flag)
result+=power(2, spec.e+spec.f);
if(NaN_flag)
{
result+=power(2, spec.f)*spec.max_exponent();
result+=1;
}
else if(infinity_flag)
{
result+=power(2, spec.f)*spec.max_exponent();
}
else if(fraction==0 && exponent==0)
{
// zero
}
else if(is_normal()) // normal?
{
// fraction -- need to hide hidden bit
result+=fraction-power(2, spec.f); // hidden bit
// exponent -- bias!
result+=power(2, spec.f)*(exponent+spec.bias());
}
else // denormal
{
result+=fraction; // denormal -- no hidden bit
// the exponent is zero
}
return result;
}
void ieee_float_valuet::extract_base2(
mp_integer &_fraction,
mp_integer &_exponent) const
{
if(is_zero() || is_NaN() || is_infinity())
{
_fraction=_exponent=0;
return;
}
_exponent=exponent;
_fraction=fraction;
// adjust exponent
_exponent-=spec.f;
// try to integer-ize
while((_fraction%2)==0)
{
_fraction/=2;
++_exponent;
}
}
void ieee_float_valuet::extract_base10(
mp_integer &_fraction,
mp_integer &_exponent) const
{
if(is_zero() || is_NaN() || is_infinity())
{
_fraction=_exponent=0;
return;
}
_exponent=exponent;
_fraction=fraction;
// adjust exponent
_exponent-=spec.f;
// now make it base 10
if(_exponent>=0)
{
_fraction*=power(2, _exponent);
_exponent=0;
}
else // _exponent<0
{
// 10/2=5 -- this makes it base 10
_fraction*=power(5, -_exponent);
}
// try to re-normalize
while((_fraction%10)==0)
{
_fraction/=10;
++_exponent;
}
}
ieee_float_valuet ieee_float_valuet::one(const ieee_float_spect &spec)
{
ieee_float_valuet result{spec};
result.exponent = 0;
result.fraction = power(2, result.spec.f);
return result;
}
ieee_float_valuet ieee_float_valuet::one(const floatbv_typet &type)
{
return one(ieee_float_spect{type});
}
/// Note that calling from_double -> to_double can return different bit patterns
/// for NaN.
double ieee_float_valuet::to_double() const
{
PRECONDITION(spec == ieee_float_spect::double_precision());
union
{
double f;
uint64_t i;
} a;
if(infinity_flag)
{
if(sign_flag)
return -std::numeric_limits<double>::infinity();
else
return std::numeric_limits<double>::infinity();
}
if(NaN_flag)
{
if(sign_flag)
return -std::numeric_limits<double>::quiet_NaN();
else
return std::numeric_limits<double>::quiet_NaN();
}
mp_integer i = pack();
CHECK_RETURN(i.is_ulong());
CHECK_RETURN(i <= std::numeric_limits<std::uint64_t>::max());
a.i = i.to_ulong();
return a.f;
}
/// Note that calling from_float -> to_float can return different bit patterns
/// for NaN.
float ieee_float_valuet::to_float() const
{
// if false - ieee_floatt::to_float not supported on this architecture
static_assert(
std::numeric_limits<float>::is_iec559,
"this requires the float layout is according to the IEC 559/IEEE 754 "
"standard");
static_assert(
sizeof(float) == sizeof(uint32_t), "a 32 bit float type is required");
union
{
float f;
uint32_t i;
} a;
if(infinity_flag)
{
if(sign_flag)
return -std::numeric_limits<float>::infinity();
else
return std::numeric_limits<float>::infinity();
}
if(NaN_flag)
{
if(sign_flag)
return -std::numeric_limits<float>::quiet_NaN();
else
return std::numeric_limits<float>::quiet_NaN();
}
a.i = numeric_cast_v<uint32_t>(pack());
return a.f;
}
constant_exprt ieee_floatt::rounding_mode_expr(rounding_modet rm)
{
return floatbv_rounding_mode(static_cast<unsigned>(rm));
}
void ieee_floatt::build(
const mp_integer &_fraction,
const mp_integer &_exponent)
{
sign_flag=_fraction<0;
fraction=_fraction;
if(sign_flag)
fraction=-fraction;
exponent=_exponent;
exponent+=spec.f;
align();
}
constant_exprt ieee_float_valuet::to_expr() const
{
return constant_exprt(integer2bvrep(pack(), spec.width()), spec.to_type());
}
bool ieee_float_valuet::operator<(const ieee_float_valuet &other) const
{
PRECONDITION(other.spec == spec);
if(NaN_flag || other.NaN_flag)
return false;
// check both zero?
if(is_zero() && other.is_zero())
return false;
// one of them zero?
if(is_zero())
return !other.sign_flag;
else if(other.is_zero())
return sign_flag;
// check sign
if(sign_flag != other.sign_flag)
return sign_flag;
// handle infinity
if(infinity_flag)
{
if(other.infinity_flag)
return false;
else
return sign_flag;
}
else if(other.infinity_flag)
return !sign_flag;
// check exponent
if(exponent != other.exponent)
{
if(sign_flag) // both negative
return exponent > other.exponent;
else
return exponent < other.exponent;
}
// check significand
if(sign_flag) // both negative
return fraction > other.fraction;
else
return fraction < other.fraction;
}
bool ieee_float_valuet::operator<=(const ieee_float_valuet &other) const
{
PRECONDITION(other.spec == spec);
if(NaN_flag || other.NaN_flag)
return false;
// check zero
if(is_zero() && other.is_zero())
return true;
// handle infinity
if(infinity_flag && other.infinity_flag && sign_flag == other.sign_flag)
return true;
if(
!infinity_flag && !other.infinity_flag && sign_flag == other.sign_flag &&
exponent == other.exponent && fraction == other.fraction)
return true;
return *this < other;
}
bool ieee_float_valuet::operator>(const ieee_float_valuet &other) const
{
return other < *this;
}
bool ieee_float_valuet::operator>=(const ieee_float_valuet &other) const
{
return other <= *this;
}
bool ieee_float_valuet::operator==(const ieee_float_valuet &other) const
{
PRECONDITION(other.spec == spec);
// packed equality!
if(NaN_flag && other.NaN_flag)
return true;
else if(NaN_flag || other.NaN_flag)
return false;
if(infinity_flag && other.infinity_flag && sign_flag == other.sign_flag)
return true;
else if(infinity_flag || other.infinity_flag)
return false;
// if(a.is_zero() && b.is_zero()) return true;
return exponent == other.exponent && fraction == other.fraction &&
sign_flag == other.sign_flag;
}
bool ieee_float_valuet::ieee_equal(const ieee_float_valuet &other) const
{
PRECONDITION(other.spec == spec);
if(NaN_flag || other.NaN_flag)
return false;
if(is_zero() && other.is_zero())
return true;
PRECONDITION(spec == other.spec);
return *this == other;
}
bool ieee_float_valuet::operator==(int i) const
{
auto rm = ieee_floatt::rounding_modet::ROUND_TO_ZERO;
ieee_floatt other(spec, rm);
other.from_integer(i);
return *this == other;
}
bool ieee_float_valuet::operator!=(const ieee_float_valuet &other) const
{
return !(*this == other);
}
bool ieee_float_valuet::ieee_not_equal(const ieee_float_valuet &other) const
{
PRECONDITION(other.spec == spec);
if(NaN_flag || other.NaN_flag)
return true; // !!!
if(is_zero() && other.is_zero())
return false;
PRECONDITION(spec == other.spec);
return *this != other;
}
/// Sets *this to the next representable number closer to plus infinity (greater
/// = true) or minus infinity (greater = false).
void ieee_float_valuet::next_representable(bool greater)
{
if(is_NaN())
return;
bool old_sign = get_sign();
if(is_zero())
{
unpack(1);
set_sign(!greater);
return;
}
if(is_infinity())
{
if(get_sign() == greater)
{
make_fltmax();
set_sign(old_sign);
}
return;
}
bool dir;
if(greater)
dir = !get_sign();
else
dir = get_sign();
set_sign(false);
mp_integer old = pack();
if(dir)
++old;
else
--old;
unpack(old);
// sign change impossible (zero case caught earlier)
set_sign(old_sign);
}
/// compute f * (10^e)
void ieee_floatt::from_base10(
const mp_integer &_fraction,
const mp_integer &_exponent)
{
NaN_flag=infinity_flag=false;
sign_flag=_fraction<0;
fraction=_fraction;
if(sign_flag)
fraction=-fraction;
exponent=spec.f;
exponent+=_exponent;
if(_exponent<0)
{
// bring to max. precision
mp_integer e_power=power(2, spec.e);
fraction*=power(2, e_power);
exponent-=e_power;
fraction/=power(5, -_exponent);
}
else if(_exponent>0)
{
// fix base
fraction*=power(5, _exponent);
}
align();
}
void ieee_floatt::from_integer(const mp_integer &i)
{
NaN_flag=infinity_flag=sign_flag=false;
exponent=spec.f;
fraction=i;
align();
}
void ieee_floatt::align()
{
// NaN?
if(NaN_flag)
{
fraction=0;
exponent=0;
sign_flag=false;
return;
}
// do sign
if(fraction<0)
{
sign_flag=!sign_flag;
fraction=-fraction;
}
// zero?
if(fraction==0)
{
exponent=0;
return;
}
// 'usual case'
mp_integer f_power=power(2, spec.f);
mp_integer f_power_next=power(2, spec.f+1);
std::size_t lowPower2=fraction.floorPow2();
mp_integer exponent_offset=0;
if(lowPower2<spec.f) // too small
{
exponent_offset-=(spec.f-lowPower2);
INVARIANT(
fraction * power(2, (spec.f - lowPower2)) >= f_power,
"normalisation result must be >= lower bound");
INVARIANT(
fraction * power(2, (spec.f - lowPower2)) < f_power_next,
"normalisation result must be < upper bound");
}
else if(lowPower2>spec.f) // too large
{
exponent_offset+=(lowPower2-spec.f);
INVARIANT(
fraction / power(2, (lowPower2 - spec.f)) >= f_power,
"normalisation result must be >= lower bound");
INVARIANT(
fraction / power(2, (lowPower2 - spec.f)) < f_power_next,
"normalisation result must be < upper bound");
}
mp_integer biased_exponent=exponent+exponent_offset+spec.bias();
// exponent too large (infinity)?
if(biased_exponent>=spec.max_exponent())
{
// we need to consider the rounding mode here
switch(rounding_mode())
{
case UNKNOWN:
case NONDETERMINISTIC:
case ROUND_TO_EVEN:
infinity_flag=true;
break;
case ROUND_TO_MINUS_INF:
// the result of the rounding is never larger than the argument
if(sign_flag)
infinity_flag=true;
else
make_fltmax();
break;
case ROUND_TO_PLUS_INF:
// the result of the rounding is never smaller than the argument
if(sign_flag)
{
make_fltmax();
sign_flag=true; // restore sign
}
else
infinity_flag=true;
break;
case ROUND_TO_ZERO:
if(sign_flag)
{
make_fltmax();
sign_flag=true; // restore sign
}
else
make_fltmax(); // positive
break;
case ROUND_TO_AWAY:
// round towards + or - infinity
infinity_flag = true;
break;
}
return; // done
}
else if(biased_exponent<=0) // exponent too small?
{
// produce a denormal (or zero)
mp_integer new_exponent=mp_integer(1)-spec.bias();
exponent_offset=new_exponent-exponent;
}
exponent+=exponent_offset;
if(exponent_offset>0)
{
divide_and_round(fraction, power(2, exponent_offset));
// rounding might make the fraction too big!
if(fraction==f_power_next)
{
fraction=f_power;
++exponent;
}
}
else if(exponent_offset<0)
fraction*=power(2, -exponent_offset);
if(fraction==0)
exponent=0;
}
void ieee_floatt::divide_and_round(
mp_integer ÷nd,
const mp_integer &divisor)
{
const mp_integer remainder = dividend % divisor;
dividend /= divisor;
if(remainder!=0)
{
switch(rounding_mode())
{
case ROUND_TO_EVEN:
{
mp_integer divisor_middle = divisor / 2;
if(remainder < divisor_middle)
{
// crop
}
else if(remainder > divisor_middle)
{
++dividend;
}
else // exactly in the middle -- go to even
{
if((dividend % 2) != 0)
++dividend;
}
}
break;
case ROUND_TO_ZERO:
// this means just crop
break;
case ROUND_TO_MINUS_INF:
if(sign_flag)
++dividend;
break;
case ROUND_TO_PLUS_INF:
if(!sign_flag)
++dividend;
break;
case ROUND_TO_AWAY:
++dividend;
break;
case NONDETERMINISTIC:
case UNKNOWN:
UNREACHABLE;
}
}
}
ieee_floatt &ieee_floatt::operator/=(const ieee_floatt &other)
{
PRECONDITION(other.spec.f == spec.f);
// NaN/x = NaN
if(NaN_flag)
return *this;
// x/NaN = NaN
if(other.NaN_flag)
{
make_NaN();
return *this;