CBMC
Loading...
Searching...
No Matches
math.c
Go to the documentation of this file.
1/* FUNCTION: fabs */
2
3double fabs(double d)
4{
5 return __CPROVER_fabs(d);
6}
7
8/* FUNCTION: fabsl */
9
10long double fabsl(long double d)
11{
12 return __CPROVER_fabsl(d);
13}
14
15/* FUNCTION: fabsf */
16
17float fabsf(float f)
18{
19 return __CPROVER_fabsf(f);
20}
21
22/* FUNCTION: __builtin_fabs */
23
24double __builtin_fabs(double d)
25{
26 return __CPROVER_fabs(d);
27}
28
29/* FUNCTION: __builtin_fabsl */
30
31long double __builtin_fabsl(long double d)
32{
33 return __CPROVER_fabsl(d);
34}
35
36/* FUNCTION: __builtin_fabsf */
37
38float __builtin_fabsf(float f)
39{
40 return __CPROVER_fabsf(f);
41}
42
43/* FUNCTION: __CPROVER_isgreaterf */
44
45int __CPROVER_isgreaterf(float f, float g) { return f > g; }
46
47/* FUNCTION: __CPROVER_isgreaterd */
48
49int __CPROVER_isgreaterd(double f, double g) { return f > g; }
50
51/* FUNCTION: __CPROVER_isgreaterequalf */
52
53int __CPROVER_isgreaterequalf(float f, float g) { return f >= g; }
54
55/* FUNCTION: __CPROVER_isgreaterequald */
56
57int __CPROVER_isgreaterequald(double f, double g) { return f >= g; }
58
59/* FUNCTION: __CPROVER_islessf */
60
61int __CPROVER_islessf(float f, float g) { return f < g;}
62
63/* FUNCTION: __CPROVER_islessd */
64
65int __CPROVER_islessd(double f, double g) { return f < g;}
66
67/* FUNCTION: __CPROVER_islessequalf */
68
69int __CPROVER_islessequalf(float f, float g) { return f <= g; }
70
71/* FUNCTION: __CPROVER_islessequald */
72
73int __CPROVER_islessequald(double f, double g) { return f <= g; }
74
75/* FUNCTION: __CPROVER_islessgreaterf */
76
77int __CPROVER_islessgreaterf(float f, float g) { return (f < g) || (f > g); }
78
79/* FUNCTION: __CPROVER_islessgreaterd */
80
81int __CPROVER_islessgreaterd(double f, double g) { return (f < g) || (f > g); }
82
83/* FUNCTION: __CPROVER_isunorderedf */
84
85int __CPROVER_isunorderedf(float f, float g)
86{
88}
89
90/* FUNCTION: __CPROVER_isunorderedd */
91
92int __CPROVER_isunorderedd(double f, double g)
93{
95}
96
97/* FUNCTION: isfinite */
98
99#undef isfinite
100
101int isfinite(double d) { return __CPROVER_isfinited(d); }
102
103/* FUNCTION: __finite */
104
105int __finite(double d) { return __CPROVER_isfinited(d); }
106
107/* FUNCTION: __finitef */
108
109int __finitef(float f) { return __CPROVER_isfinitef(f); }
110
111/* FUNCTION: __finitel */
112
113int __finitel(long double ld) { return __CPROVER_isfiniteld(ld); }
114
115/* FUNCTION: isinf */
116
117#undef isinf
118
119int isinf(double d)
120{
121 return __CPROVER_isinfd(d);
122}
123
124/* FUNCTION: __isinf */
125
126int __isinf(double d)
127{
128 return __CPROVER_isinfd(d);
129}
130
131/* FUNCTION: isinff */
132
133int isinff(float f)
134{
135 return __CPROVER_isinff(f);
136}
137
138/* FUNCTION: __isinff */
139
140int __isinff(float f)
141{
142 return __CPROVER_isinff(f);
143}
144
145/* FUNCTION: isinfl */
146
147int isinfl(long double ld)
148{
149 return __CPROVER_isinfld(ld);
150}
151
152/* FUNCTION: __isinfl */
153
154int __isinfl(long double ld)
155{
156 return __CPROVER_isinfld(ld);
157}
158
159/* FUNCTION: isnan */
160
161#undef isnan
162
163int isnan(double d)
164{
165 return __CPROVER_isnand(d);
166}
167
168/* FUNCTION: __isnan */
169
170int __isnan(double d)
171{
172 return __CPROVER_isnand(d);
173}
174
175/* FUNCTION: __isnanf */
176
177int __isnanf(float f)
178{
179 return __CPROVER_isnanf(f);
180}
181
182/* FUNCTION: isnanf */
183
184int isnanf(float f)
185{
186 return __CPROVER_isnanf(f);
187}
188
189/* FUNCTION: isnanl */
190
191int isnanl(long double ld)
192{
193 return __CPROVER_isnanld(ld);
194}
195
196/* FUNCTION: __isnanl */
197
198int __isnanl(long double ld)
199{
200 return __CPROVER_isnanld(ld);
201}
202
203/* FUNCTION: isnormal */
204
205#undef isnormal
206
207int isnormal(double d)
208{
209 return __CPROVER_isnormald(d);
210}
211
212/* FUNCTION: __isnormalf */
213
214int __isnormalf(float f)
215{
216 return __CPROVER_isnormalf(f);
217}
218
219/* FUNCTION: __builtin_inff */
220
221float __builtin_inff(void)
222{
223#pragma CPROVER check push
224#pragma CPROVER check disable "float-div-by-zero"
225#pragma CPROVER check disable "float-overflow"
226 return 1.0f / 0.0f;
227#pragma CPROVER check pop
228}
229
230/* FUNCTION: __builtin_inf */
231
232double __builtin_inf(void)
233{
234#pragma CPROVER check push
235#pragma CPROVER check disable "float-div-by-zero"
236#pragma CPROVER check disable "float-overflow"
237 return 1.0 / 0.0;
238#pragma CPROVER check pop
239}
240
241/* FUNCTION: __builtin_infl */
242
243long double __builtin_infl(void)
244{
245#pragma CPROVER check push
246#pragma CPROVER check disable "float-div-by-zero"
247#pragma CPROVER check disable "float-overflow"
248 return 1.0l / 0.0l;
249#pragma CPROVER check pop
250}
251
252/* FUNCTION: __builtin_isinf */
253
254int __builtin_isinf(double d)
255{
256 return __CPROVER_isinfd(d);
257}
258
259/* FUNCTION: __builtin_isinff */
260
262{
263 return __CPROVER_isinff(f);
264}
265
266/* FUNCTION: __builtin_isinf */
267
268int __builtin_isinfl(long double ld)
269{
270 return __CPROVER_isinfld(ld);
271}
272
273/* FUNCTION: __builtin_isnan */
274
275int __builtin_isnan(double d)
276{
277 return __CPROVER_isnand(d);
278}
279
280/* FUNCTION: __builtin_isnanf */
281
283{
284 return __CPROVER_isnanf(f);
285}
286
287/* FUNCTION: __builtin_huge_valf */
288
290{
291#pragma CPROVER check push
292#pragma CPROVER check disable "float-div-by-zero"
293#pragma CPROVER check disable "float-overflow"
294 return 1.0f / 0.0f;
295#pragma CPROVER check pop
296}
297
298/* FUNCTION: __builtin_huge_val */
299
301{
302#pragma CPROVER check push
303#pragma CPROVER check disable "float-div-by-zero"
304#pragma CPROVER check disable "float-overflow"
305 return 1.0 / 0.0;
306#pragma CPROVER check pop
307}
308
309/* FUNCTION: __builtin_huge_vall */
310
311long double __builtin_huge_vall(void)
312{
313#pragma CPROVER check push
314#pragma CPROVER check disable "float-div-by-zero"
315#pragma CPROVER check disable "float-overflow"
316 return 1.0l / 0.0l;
317#pragma CPROVER check pop
318}
319
320/* FUNCTION: _dsign */
321
322int _dsign(double d)
323{
324 return __CPROVER_signd(d);
325}
326
327/* FUNCTION: _ldsign */
328
329int _ldsign(long double ld)
330{
331 return __CPROVER_signld(ld);
332}
333
334/* FUNCTION: _fdsign */
335
336int _fdsign(float f)
337{
338 return __CPROVER_signf(f);
339}
340
341/* FUNCTION: signbit */
342
343#undef signbit
344
345int signbit(double d)
346{
347 return __CPROVER_signd(d);
348}
349
350/* FUNCTION: __signbitd */
351
352int __signbitd(double d)
353{
354 return __CPROVER_signd(d);
355}
356
357/* FUNCTION: __signbitf */
358
359int __signbitf(float f)
360{
361 return __CPROVER_signf(f);
362}
363
364/* FUNCTION: __signbit */
365
366int __signbit(double ld)
367{
368 return __CPROVER_signld(ld);
369}
370
371/* FUNCTION: _dclass */
372
373#ifndef __CPROVER_MATH_H_INCLUDED
374#include <math.h>
375#define __CPROVER_MATH_H_INCLUDED
376#endif
377
378short _dclass(double d)
379{
381 return __CPROVER_isnand(d)?FP_NAN:
383 d==0?FP_ZERO:
386}
387
388/* FUNCTION: _ldclass */
389
390#ifndef __CPROVER_MATH_H_INCLUDED
391#include <math.h>
392#define __CPROVER_MATH_H_INCLUDED
393#endif
394
404
405/* FUNCTION: _fdclass */
406
407#ifndef __CPROVER_MATH_H_INCLUDED
408#include <math.h>
409#define __CPROVER_MATH_H_INCLUDED
410#endif
411
412short _fdclass(float f)
413{
415 return __CPROVER_isnanf(f)?FP_NAN:
417 f==0?FP_ZERO:
420}
421
422/* FUNCTION: __fpclassifyd */
423
424#ifndef __CPROVER_MATH_H_INCLUDED
425#include <math.h>
426#define __CPROVER_MATH_H_INCLUDED
427#endif
428
435
436/* FUNCTION: __fpclassifyf */
437
438#ifndef __CPROVER_MATH_H_INCLUDED
439#include <math.h>
440#define __CPROVER_MATH_H_INCLUDED
441#endif
442
449
450/* FUNCTION: __fpclassifyl */
451
452#ifndef __CPROVER_MATH_H_INCLUDED
453#include <math.h>
454#define __CPROVER_MATH_H_INCLUDED
455#endif
456
457int __fpclassifyl(long double f)
458{
462}
463
464/* FUNCTION: __fpclassify */
465
466#ifndef __CPROVER_MATH_H_INCLUDED
467#include <math.h>
468#define __CPROVER_MATH_H_INCLUDED
469#endif
470
471// The variant with long double below is needed for older Macs
472// only; newer ones use __fpclassifyd.
473
474#ifdef __APPLE__
475int __fpclassify(long double d)
476{
480}
481#else
488#endif
489
490/* FUNCTION: sin */
491
493
494double sin(double x)
495{
496 // gross over-approximation
498
501 else
502 {
505 __CPROVER_assume(x!=0 || ret==0);
506 }
507
508 return ret;
509}
510
511/* FUNCTION: sinl */
512
514
515long double sinl(long double x)
516{
517 // gross over-approximation
519
522 else
523 {
526 __CPROVER_assume(x!=0 || ret==0);
527 }
528
529 return ret;
530}
531
532/* FUNCTION: sinf */
533
535
536float sinf(float x)
537{
538 // gross over-approximation
540
543 else
544 {
547 __CPROVER_assume(x!=0 || ret==0);
548 }
549
550 return ret;
551}
552
553/* FUNCTION: cos */
554
555double __VERIFIER_nondet_double(void);
556
557double cos(double x)
558{
559 // gross over-approximation
561
564 else
565 {
568 __CPROVER_assume(x!=0 || ret==1);
569 }
570
571 return ret;
572}
573
574/* FUNCTION: cosl */
575
576long double __VERIFIER_nondet_long_double(void);
577
578long double cosl(long double x)
579{
580 // gross over-approximation
582
585 else
586 {
589 __CPROVER_assume(x!=0 || ret==1);
590 }
591
592 return ret;
593}
594
595/* FUNCTION: cosf */
596
597float __VERIFIER_nondet_float(void);
598
599float cosf(float x)
600{
602 // gross over-approximation
604
607 else
608 {
611 __CPROVER_assume(x!=0 || ret==1);
612 }
613
614 return ret;
615}
616
617/* FUNCTION: __builtin_nan */
618
619double __builtin_nan(const char *str)
620{
621 // the 'str' argument is not yet used
623 (void)*str;
624#pragma CPROVER check push
625#pragma CPROVER check disable "float-div-by-zero"
626 return 0.0/0.0;
627#pragma CPROVER check pop
628}
629
630/* FUNCTION: __builtin_nanf */
631
632float __builtin_nanf(const char *str)
633{
634 // the 'str' argument is not yet used
636 (void)*str;
637#pragma CPROVER check push
638#pragma CPROVER check disable "float-div-by-zero"
639 return 0.0f/0.0f;
640#pragma CPROVER check pop
641}
642
643
644/* ISO 9899:2011
645 * The call nan("n-char-sequence") is equivalent to
646 * strtod("NAN(n-char-sequence)", (char**) NULL); the call nan("") is
647 * equivalent to strtod("NAN()", (char**) NULL). If tagp does not
648 * point to an n-char sequence or an empty string, the call is
649 * equivalent to strtod("NAN", (char**) NULL). Calls to nanf and nanl
650 * are equivalent to the corresponding calls to strtof and strtold.
651 *
652 * The nan functions return a quiet NaN, if available, with content
653 * indicated through tagp. If the implementation does not support
654 * quiet NaNs, the functions return zero.
655 */
656
657/* FUNCTION: nan */
658
659double nan(const char *str) {
660 // the 'str' argument is not yet used
662 (void)*str;
663#pragma CPROVER check push
664#pragma CPROVER check disable "float-div-by-zero"
665 return 0.0/0.0;
666#pragma CPROVER check pop
667}
668
669/* FUNCTION: nanf */
670
671float nanf(const char *str) {
672 // the 'str' argument is not yet used
674 (void)*str;
675#pragma CPROVER check push
676#pragma CPROVER check disable "float-div-by-zero"
677 return 0.0f/0.0f;
678#pragma CPROVER check pop
679}
680
681/* FUNCTION: nanl */
682
683long double nanl(const char *str) {
684 // the 'str' argument is not yet used
686 (void)*str;
687#pragma CPROVER check push
688#pragma CPROVER check disable "float-div-by-zero"
689 return 0.0/0.0;
690#pragma CPROVER check pop
691}
692
693/* FUNCTION: nextUpf */
694
695#ifndef __CPROVER_LIMITS_H_INCLUDED
696#include <limits.h>
697#define __CPROVER_LIMITS_H_INCLUDED
698#endif
699
700
701// IEEE_754 2008 althought similar to C's nextafter / nexttowards
702// Loosely assumes that float is (IEEE-754) binary32
703
704union mixf
705{
706 float f;
707 #ifdef LIBRARY_CHECK
708 int bv;
709 #else
711 #endif
712};
713
714float nextUpf(float f)
715{
717 if (__CPROVER_isnanf(f))
718#pragma CPROVER check push
719#pragma CPROVER check disable "float-div-by-zero"
720 return 0.0f/0.0f; // NaN
721#pragma CPROVER check pop
722 else if (f == 0.0f)
723 return 0x1p-149f;
724 else if (f > 0.0f)
725 {
726 if (__CPROVER_isinff(f))
727 return f;
728
729 union mixf m;
730 m.f = f;
731 ++m.bv;
732 return m.f;
733 }
734 else
735 {
736 //assert(f < 0.0f);
737
738 union mixf m;
739 m.f = f;
740 --m.bv;
741 return m.f;
742 }
743}
744
745/* FUNCTION: nextUp */
746
747#ifndef __CPROVER_LIMITS_H_INCLUDED
748#include <limits.h>
749#define __CPROVER_LIMITS_H_INCLUDED
750#endif
751
752
753// IEEE_754 2008 althought similar to C's nextafter / nexttowards
754// Loosely assumes that double is (IEEE-754) binary64
755
756union mixd
757{
758 double f;
759 #ifdef LIBRARY_CHECK
760 long long int bv;
761 #else
763 #endif
764};
765
766double nextUp(double d)
767{
769 if (__CPROVER_isnand(d))
770#pragma CPROVER check push
771#pragma CPROVER check disable "float-div-by-zero"
772 return 0.0/0.0; // NaN
773#pragma CPROVER check pop
774 else if (d == 0.0)
775 return 0x1.0p-1074;
776 else if (d > 0.0)
777 {
778 if (__CPROVER_isinfd(d))
779 return d;
780
781 union mixd m;
782 m.f = d;
783 ++m.bv;
784 return m.f;
785 }
786 else
787 {
788 //assert(d < 0.0);
789
790 union mixd m;
791 m.f = d;
792 --m.bv;
793 return m.f;
794 }
795}
796
797
798/* FUNCTION: nextUpl */
799
800#ifndef __CPROVER_LIMITS_H_INCLUDED
801#include <limits.h>
802#define __CPROVER_LIMITS_H_INCLUDED
803#endif
804
805// IEEE_754 2008 althought similar to C's nextafter / nexttowards
806
807union mixl
808{
809 long double f;
810 #ifdef LIBRARY_CHECK
811 long long int bv;
812 #else
814 #endif
815};
816
817long double nextUpl(long double d)
818{
820 if(__CPROVER_isnanld(d))
821#pragma CPROVER check push
822#pragma CPROVER check disable "float-div-by-zero"
823 return 0.0/0.0; // NaN
824#pragma CPROVER check pop
825 else if (d == 0.0)
826 {
827 union mixl m;
828 m.bv = 0x1;
829 return m.f;
830 }
831 else if (d > 0.0)
832 {
833 if(__CPROVER_isinfld(d))
834 return d;
835
836 union mixl m;
837 m.f = d;
838 ++m.bv;
839 return m.f;
840 }
841 else
842 {
843 //assert(d < 0.0);
844
845 union mixl m;
846 m.f = d;
847 --m.bv;
848 return m.f;
849 }
850
851}
852
853
854
855
856/* FUNCTION: sqrtf */
857
858/* This code is *WRONG* in some circumstances, specifically:
859 *
860 * 1. If run with a rounding mode other than RNE the
861 * answer will be out by one or two ULP. This could be fixed
862 * with careful choice of round mode for the multiplications.
863 *
864 * 2. Subnormals have the unusual property that there are
865 * multiple numbers that square to give them. I.E. if
866 * f is subnormal then there are multiple f1 != f2 such that
867 * f1 * f1 == f == f2 * f2. This code will return *a*
868 * square root of a subnormal input but not necessarily *the*
869 * square root (i.e. the real value of the square root rounded).
870 */
871
872#ifndef __CPROVER_MATH_H_INCLUDED
873#include <math.h>
874#define __CPROVER_MATH_H_INCLUDED
875#endif
876
877#ifndef __CPROVER_FENV_H_INCLUDED
878#include <fenv.h>
879#define __CPROVER_FENV_H_INCLUDED
880#endif
881
882float nextUpf(float f);
883
884float __VERIFIER_nondet_float(void);
885
886float sqrtf(float f)
887{
889
890 if ( f < 0.0f )
891#pragma CPROVER check push
892#pragma CPROVER check disable "float-div-by-zero"
893 return 0.0f/0.0f; // NaN
894#pragma CPROVER check pop
895 else if (__CPROVER_isinff(f) || // +Inf only
896 f == 0.0f || // Includes -0
898 return f;
899 else if (__CPROVER_isnormalf(f))
900 {
901 float lower=__VERIFIER_nondet_float();
902 __CPROVER_assume(lower > 0.0f);
904 // Tighter bounds can be given but are dependent on the
905 // number of exponent and significand bits. Thus they are
906 // given implicitly...
907
908#pragma CPROVER check push
909#pragma CPROVER check disable "float-overflow"
910 float lowerSquare = lower * lower;
912
913 float upper = nextUpf(lower);
914 float upperSquare = upper * upper; // Might be +Inf
915#pragma CPROVER check pop
916
917 // Restrict these to bound f and thus compute the possible
918 // values for the square root. Note that the lower bound
919 // can be equal, this is important to catch edge cases such as
920 // 0x1.fffffep+127f and relies on the smallest normal number
921 // being a perfect square (which it will be for any sensible
922 // bit width).
925
926 // Select between them to work out which to return
927 switch(fegetround())
928 {
929 case FE_TONEAREST :
930 return (f - lowerSquare < upperSquare - f) ? lower : upper; break;
931 case FE_UPWARD :
932 return (f - lowerSquare == 0.0f) ? lower : upper; break;
933 case FE_DOWNWARD : // Fall through
934 case FE_TOWARDZERO :
935 return (f - lowerSquare == 0.0f) ? lower : upper; break;
936 default:;
938 }
939
940 }
941 else
942 {
943 //assert(fpclassify(f) == FP_SUBNORMAL);
944 //assert(f > 0.0f);
945
946 // With respect to the algebra of floating point number
947 // all subnormals seem to be perfect squares, thus ...
948
949 float root=__VERIFIER_nondet_float();
950 __CPROVER_assume(root >= 0.0f);
951
952 __CPROVER_assume(root * root == f);
953
954 return root;
955 }
956}
957
958
959
960
961/* FUNCTION: sqrt */
962
963/* The same caveats as sqrtf apply */
964
965#ifndef __CPROVER_MATH_H_INCLUDED
966#include <math.h>
967#define __CPROVER_MATH_H_INCLUDED
968#endif
969
970#ifndef __CPROVER_FENV_H_INCLUDED
971#include <fenv.h>
972#define __CPROVER_FENV_H_INCLUDED
973#endif
974
975double nextUp(double d);
976
977double __VERIFIER_nondet_double(void);
978
979double sqrt(double d)
980{
982
983 if ( d < 0.0 )
984#pragma CPROVER check push
985#pragma CPROVER check disable "float-div-by-zero"
986 return 0.0/0.0; // NaN
987#pragma CPROVER check pop
988 else if (__CPROVER_isinfd(d) || // +Inf only
989 d == 0.0 || // Includes -0
991 return d;
992 else if (__CPROVER_isnormald(d))
993 {
994 double lower=__VERIFIER_nondet_double();
995 __CPROVER_assume(lower > 0.0);
997
998#pragma CPROVER check push
999#pragma CPROVER check disable "float-overflow"
1000 double lowerSquare = lower * lower;
1002
1003 double upper = nextUp(lower);
1004 double upperSquare = upper * upper; // Might be +Inf
1005#pragma CPROVER check pop
1006
1009
1010 switch(fegetround())
1011 {
1012 case FE_TONEAREST:
1013 return (d - lowerSquare < upperSquare - d) ? lower : upper; break;
1014 case FE_UPWARD:
1015 return (d - lowerSquare == 0.0f) ? lower : upper; break;
1016 case FE_DOWNWARD: // Fall through
1017 case FE_TOWARDZERO:
1018 return (d - lowerSquare == 0.0) ? lower : upper; break;
1019 default:;
1020 return __VERIFIER_nondet_double();
1021 }
1022
1023 }
1024 else
1025 {
1026 //assert(fpclassify(d) == FP_SUBNORMAL);
1027 //assert(d > 0.0);
1028
1029 double root=__VERIFIER_nondet_double();
1030 __CPROVER_assume(root >= 0.0);
1031
1032 __CPROVER_assume(root * root == d);
1033
1034 return root;
1035 }
1036}
1037
1038/* FUNCTION: sqrtl */
1039
1040/* The same caveats as sqrtf apply */
1041
1042#ifndef __CPROVER_MATH_H_INCLUDED
1043#include <math.h>
1044#define __CPROVER_MATH_H_INCLUDED
1045#endif
1046
1047#ifndef __CPROVER_FENV_H_INCLUDED
1048#include <fenv.h>
1049#define __CPROVER_FENV_H_INCLUDED
1050#endif
1051
1052long double nextUpl(long double d);
1053
1054long double __VERIFIER_nondet_long_double(void);
1055
1056long double sqrtl(long double d)
1057{
1059
1060 if(d < 0.0l)
1061#pragma CPROVER check push
1062#pragma CPROVER check disable "float-div-by-zero"
1063 return 0.0l/0.0l; // NaN
1064#pragma CPROVER check pop
1065 else if (__CPROVER_isinfld(d) || // +Inf only
1066 d == 0.0l || // Includes -0
1068 return d;
1069 else if (__CPROVER_isnormalld(d))
1070 {
1071 long double lower=__VERIFIER_nondet_long_double();
1072 __CPROVER_assume(lower > 0.0l);
1074
1075#pragma CPROVER check push
1076#pragma CPROVER check disable "float-overflow"
1077 long double lowerSquare = lower * lower;
1079
1080 long double upper = nextUpl(lower);
1081 long double upperSquare = upper * upper; // Might be +Inf
1082#pragma CPROVER check pop
1083
1086
1087 switch(fegetround())
1088 {
1089 case FE_TONEAREST:
1090 return (d - lowerSquare < upperSquare - d) ? lower : upper; break;
1091 case FE_UPWARD:
1092 return (d - lowerSquare == 0.0l) ? lower : upper; break;
1093 case FE_DOWNWARD: // Fall through
1094 case FE_TOWARDZERO:
1095 return (d - lowerSquare == 0.0l) ? lower : upper; break;
1096 default:;
1098 }
1099
1100 }
1101 else
1102 {
1103 //assert(fpclassify(d) == FP_SUBNORMAL);
1104 //assert(d > 0.0l);
1105
1106 long double root=__VERIFIER_nondet_long_double();
1107 __CPROVER_assume(root >= 0.0l);
1108
1109 __CPROVER_assume(root * root == d);
1110
1111 return root;
1112 }
1113}
1114
1115
1116/* ISO 9899:2011
1117 * The fmax functions determine the maximum numeric value of their
1118 * arguments. 242)
1119 *
1120 * 242) NaN arguments are treated as missing data: if one argument is
1121 * a NaN and the other numeric, then the fmax functions choose the
1122 * numeric value. See F.10.9.2.
1123 *
1124 * - If just one argument is a NaN, the fmax functions return the other
1125 * argument (if both arguments are NaNs, the functions return a NaN).
1126 * - The returned value is exact and is independent of the current
1127 * rounding direction mode.
1128 * - The body of the fmax function might be 374)
1129 * { return (isgreaterequal(x, y) || isnan(y)) ? x : y; }
1130 *
1131 * 374) Ideally, fmax would be sensitive to the sign of zero, for
1132 * example fmax(-0.0, +0.0) would return +0; however, implementation
1133 * in software might be impractical.
1134 */
1135
1136/* FUNCTION: fmax */
1137
1138#ifndef __CPROVER_MATH_H_INCLUDED
1139#include <math.h>
1140#define __CPROVER_MATH_H_INCLUDED
1141#endif
1142
1143// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
1144double fmax(double f, double g) { return ((f >= g) || isnan(g)) ? f : g; }
1145
1146/* FUNCTION: fmaxf */
1147
1148#ifndef __CPROVER_MATH_H_INCLUDED
1149#include <math.h>
1150#define __CPROVER_MATH_H_INCLUDED
1151#endif
1152
1153// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
1154float fmaxf(float f, float g) { return ((f >= g) || isnan(g)) ? f : g; }
1155
1156/* FUNCTION: fmaxl */
1157
1158#ifndef __CPROVER_MATH_H_INCLUDED
1159#include <math.h>
1160#define __CPROVER_MATH_H_INCLUDED
1161#endif
1162
1163// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
1164long double fmaxl(long double f, long double g) { return ((f >= g) || isnan(g)) ? f : g; }
1165
1166
1167/* ISO 9899:2011
1168 * The fmin functions determine the minimum numeric value of their
1169 * arguments.243)
1170 *
1171 * 243) The fmin functions are analogous to the fmax functions in
1172 * their treatment of NaNs.
1173 *
1174 * - The fmin functions are analogous to the fmax functions (see F.10.9.2).
1175 * - The returned value is exact and is independent of the current
1176 * rounding direction mode.
1177 */
1178
1179/* FUNCTION: fmin */
1180
1181#ifndef __CPROVER_MATH_H_INCLUDED
1182#include <math.h>
1183#define __CPROVER_MATH_H_INCLUDED
1184#endif
1185
1186// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
1187double fmin(double f, double g) { return ((f <= g) || isnan(g)) ? f : g; }
1188
1189/* FUNCTION: fminf */
1190
1191#ifndef __CPROVER_MATH_H_INCLUDED
1192#include <math.h>
1193#define __CPROVER_MATH_H_INCLUDED
1194#endif
1195
1196// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
1197float fminf(float f, float g) { return ((f <= g) || isnan(g)) ? f : g; }
1198
1199/* FUNCTION: fminl */
1200
1201#ifndef __CPROVER_MATH_H_INCLUDED
1202#include <math.h>
1203#define __CPROVER_MATH_H_INCLUDED
1204#endif
1205
1206// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
1207long double fminl(long double f, long double g) { return ((f <= g) || isnan(g)) ? f : g; }
1208
1209
1210/* ISO 9899:2011
1211 * The fdim functions determine the positive difference between their
1212 * arguments:
1213 * x - y if x > y
1214 * +0 if x <= y
1215 * A range error may occur.
1216 */
1217
1218/* FUNCTION: fdim */
1219
1220#ifndef __CPROVER_MATH_H_INCLUDED
1221#include <math.h>
1222#define __CPROVER_MATH_H_INCLUDED
1223#endif
1224
1225double fdim(double f, double g) { return ((f > g) ? f - g : +0.0); }
1226
1227
1228/* FUNCTION: fdimf */
1229
1230#ifndef __CPROVER_MATH_H_INCLUDED
1231#include <math.h>
1232#define __CPROVER_MATH_H_INCLUDED
1233#endif
1234
1235float fdimf(float f, float g) { return ((f > g) ? f - g : +0.0f); }
1236
1237
1238/* FUNCTION: fdiml */
1239
1240#ifndef __CPROVER_MATH_H_INCLUDED
1241#include <math.h>
1242#define __CPROVER_MATH_H_INCLUDED
1243#endif
1244
1245long double fdiml(long double f, long double g) { return ((f > g) ? f - g : +0.0); }
1246
1247/* ISO 9899:2011
1248 *
1249 * The ceil functions compute the smallest integer value not less than
1250 * x.
1251 */
1252
1253/* FUNCTION: ceil */
1254
1255#ifndef __CPROVER_MATH_H_INCLUDED
1256#include <math.h>
1257#define __CPROVER_MATH_H_INCLUDED
1258#endif
1259
1260#ifndef __CPROVER_FENV_H_INCLUDED
1261#include <fenv.h>
1262#define __CPROVER_FENV_H_INCLUDED
1263#endif
1264
1265double ceil(double x)
1266{
1267 return __CPROVER_round_to_integrald(x, 2); // FE_UPWARD
1268}
1269
1270/* FUNCTION: ceilf */
1271
1272#ifndef __CPROVER_MATH_H_INCLUDED
1273#include <math.h>
1274#define __CPROVER_MATH_H_INCLUDED
1275#endif
1276
1277#ifndef __CPROVER_FENV_H_INCLUDED
1278#include <fenv.h>
1279#define __CPROVER_FENV_H_INCLUDED
1280#endif
1281
1282float ceilf(float x)
1283{
1284 return __CPROVER_round_to_integralf(x, 2); // FE_UPWARD
1285}
1286
1287
1288/* FUNCTION: ceill */
1289
1290#ifndef __CPROVER_MATH_H_INCLUDED
1291#include <math.h>
1292#define __CPROVER_MATH_H_INCLUDED
1293#endif
1294
1295#ifndef __CPROVER_FENV_H_INCLUDED
1296#include <fenv.h>
1297#define __CPROVER_FENV_H_INCLUDED
1298#endif
1299
1300long double ceill(long double x)
1301{
1302 return __CPROVER_round_to_integralld(x, 2); // FE_UPWARD
1303}
1304
1305
1306/* ISO 9899:2011
1307 *
1308 * The floor functions compute the largest integer value not greater than x.
1309 */
1310
1311/* FUNCTION: floor */
1312
1313#ifndef __CPROVER_MATH_H_INCLUDED
1314#include <math.h>
1315#define __CPROVER_MATH_H_INCLUDED
1316#endif
1317
1318#ifndef __CPROVER_FENV_H_INCLUDED
1319#include <fenv.h>
1320#define __CPROVER_FENV_H_INCLUDED
1321#endif
1322
1323double floor(double x)
1324{
1325 return __CPROVER_round_to_integrald(x, 3); // FE_DOWNWARD
1326}
1327
1328/* FUNCTION: floorf */
1329
1330#ifndef __CPROVER_MATH_H_INCLUDED
1331#include <math.h>
1332#define __CPROVER_MATH_H_INCLUDED
1333#endif
1334
1335#ifndef __CPROVER_FENV_H_INCLUDED
1336#include <fenv.h>
1337#define __CPROVER_FENV_H_INCLUDED
1338#endif
1339
1340float floorf(float x)
1341{
1342 return __CPROVER_round_to_integralf(x, 3); // FE_DOWNWARD
1343}
1344
1345
1346/* FUNCTION: floorl */
1347
1348#ifndef __CPROVER_MATH_H_INCLUDED
1349#include <math.h>
1350#define __CPROVER_MATH_H_INCLUDED
1351#endif
1352
1353#ifndef __CPROVER_FENV_H_INCLUDED
1354#include <fenv.h>
1355#define __CPROVER_FENV_H_INCLUDED
1356#endif
1357
1358long double floorl(long double x)
1359{
1360 return __CPROVER_round_to_integralld(x, 3); // FE_DOWNWARD
1361}
1362
1363
1364/* ISO 9899:2011
1365 *
1366 * The trunc functions round their argument to the integer value, in
1367 * floating format, nearest to but no larger in magnitude than the argument.
1368 */
1369
1370/* FUNCTION: trunc */
1371
1372#ifndef __CPROVER_MATH_H_INCLUDED
1373#include <math.h>
1374#define __CPROVER_MATH_H_INCLUDED
1375#endif
1376
1377#ifndef __CPROVER_FENV_H_INCLUDED
1378#include <fenv.h>
1379#define __CPROVER_FENV_H_INCLUDED
1380#endif
1381
1382double trunc(double x)
1383{
1384 return __CPROVER_round_to_integrald(x, 0); // FE_TOWARDZERO
1385}
1386
1387/* FUNCTION: truncf */
1388
1389#ifndef __CPROVER_MATH_H_INCLUDED
1390#include <math.h>
1391#define __CPROVER_MATH_H_INCLUDED
1392#endif
1393
1394#ifndef __CPROVER_FENV_H_INCLUDED
1395#include <fenv.h>
1396#define __CPROVER_FENV_H_INCLUDED
1397#endif
1398
1399float truncf(float x)
1400{
1401 return __CPROVER_round_to_integralf(x, 0); // FE_TOWARDZERO
1402}
1403
1404
1405/* FUNCTION: truncl */
1406
1407#ifndef __CPROVER_MATH_H_INCLUDED
1408#include <math.h>
1409#define __CPROVER_MATH_H_INCLUDED
1410#endif
1411
1412#ifndef __CPROVER_FENV_H_INCLUDED
1413#include <fenv.h>
1414#define __CPROVER_FENV_H_INCLUDED
1415#endif
1416
1417long double truncl(long double x)
1418{
1419 return __CPROVER_round_to_integralld(x, 0); // FE_TOWARDZERO
1420}
1421
1422
1423/* ISO 9899:2011
1424 *
1425 * The round functions round their argument to the integer value, in
1426 * floating format, nearest to but no larger in magnitude than the argument.
1427 */
1428
1429/* FUNCTION: round */
1430
1431#ifndef __CPROVER_MATH_H_INCLUDED
1432#include <math.h>
1433#define __CPROVER_MATH_H_INCLUDED
1434#endif
1435
1436#ifndef __CPROVER_FENV_H_INCLUDED
1437#include <fenv.h>
1438#define __CPROVER_FENV_H_INCLUDED
1439#endif
1440
1441double round(double x)
1442{
1443 return __CPROVER_round_to_integrald(x, 4); // RNA
1444}
1445
1446/* FUNCTION: roundf */
1447
1448#ifndef __CPROVER_MATH_H_INCLUDED
1449#include <math.h>
1450#define __CPROVER_MATH_H_INCLUDED
1451#endif
1452
1453#ifndef __CPROVER_FENV_H_INCLUDED
1454#include <fenv.h>
1455#define __CPROVER_FENV_H_INCLUDED
1456#endif
1457
1458float roundf(float x)
1459{
1460 return __CPROVER_round_to_integralf(x, 4); // RNA
1461}
1462
1463
1464/* FUNCTION: roundl */
1465
1466#ifndef __CPROVER_MATH_H_INCLUDED
1467#include <math.h>
1468#define __CPROVER_MATH_H_INCLUDED
1469#endif
1470
1471#ifndef __CPROVER_FENV_H_INCLUDED
1472#include <fenv.h>
1473#define __CPROVER_FENV_H_INCLUDED
1474#endif
1475
1476long double roundl(long double x)
1477{
1478 return __CPROVER_round_to_integralld(x, 4); // RNA
1479}
1480
1481
1482
1483/* ISO 9899:2011
1484 *
1485 * The nearbyint functions round their argument to an integer value in
1486 * floating-point format, using the current rounding direction and
1487 * without raising the inexact floating-point exception.
1488 */
1489
1490/* FUNCTION: nearbyint */
1491
1492#ifndef __CPROVER_MATH_H_INCLUDED
1493#include <math.h>
1494#define __CPROVER_MATH_H_INCLUDED
1495#endif
1496
1497#ifndef __CPROVER_FENV_H_INCLUDED
1498#include <fenv.h>
1499#define __CPROVER_FENV_H_INCLUDED
1500#endif
1501
1502extern int __CPROVER_rounding_mode;
1503
1504double nearbyint(double x)
1505{
1507}
1508
1509/* FUNCTION: nearbyintf */
1510
1511#ifndef __CPROVER_MATH_H_INCLUDED
1512#include <math.h>
1513#define __CPROVER_MATH_H_INCLUDED
1514#endif
1515
1516#ifndef __CPROVER_FENV_H_INCLUDED
1517#include <fenv.h>
1518#define __CPROVER_FENV_H_INCLUDED
1519#endif
1520
1522
1527
1528
1529/* FUNCTION: nearbyintl */
1530
1531#ifndef __CPROVER_MATH_H_INCLUDED
1532#include <math.h>
1533#define __CPROVER_MATH_H_INCLUDED
1534#endif
1535
1536#ifndef __CPROVER_FENV_H_INCLUDED
1537#include <fenv.h>
1538#define __CPROVER_FENV_H_INCLUDED
1539#endif
1540
1541extern int __CPROVER_rounding_mode;
1542
1543long double nearbyintl(long double x)
1544{
1546}
1547
1548
1549
1550/* ISO 9899:2011
1551 *
1552 * The rint functions differ from the nearbyint functions (7.12.9.3)
1553 * only in that the rint functions may raise the inexact
1554 * floating-point exception if the result differs in value from the argument.
1555 */
1556
1557/* FUNCTION: rint */
1558
1559#ifndef __CPROVER_MATH_H_INCLUDED
1560#include <math.h>
1561#define __CPROVER_MATH_H_INCLUDED
1562#endif
1563
1564#ifndef __CPROVER_FENV_H_INCLUDED
1565#include <fenv.h>
1566#define __CPROVER_FENV_H_INCLUDED
1567#endif
1568
1569extern int __CPROVER_rounding_mode;
1570
1571double rint(double x)
1572{
1574}
1575
1576/* FUNCTION: rintf */
1577
1578#ifndef __CPROVER_MATH_H_INCLUDED
1579#include <math.h>
1580#define __CPROVER_MATH_H_INCLUDED
1581#endif
1582
1583#ifndef __CPROVER_FENV_H_INCLUDED
1584#include <fenv.h>
1585#define __CPROVER_FENV_H_INCLUDED
1586#endif
1587
1588extern int __CPROVER_rounding_mode;
1589
1590float rintf(float x)
1591{
1593}
1594
1595/* FUNCTION: rintl */
1596
1597#ifndef __CPROVER_MATH_H_INCLUDED
1598#include <math.h>
1599#define __CPROVER_MATH_H_INCLUDED
1600#endif
1601
1602#ifndef __CPROVER_FENV_H_INCLUDED
1603#include <fenv.h>
1604#define __CPROVER_FENV_H_INCLUDED
1605#endif
1606
1607extern int __CPROVER_rounding_mode;
1608
1609long double rintl(long double x)
1610{
1612}
1613
1614
1615
1616/* ISO 9899:2011
1617 *
1618 * The lrint and llrint functions round their argument to the nearest
1619 * integer value, rounding according to the current rounding
1620 * direction. If the rounded value is outside the range of the return
1621 * type, the numeric result is unspecified and a domain error or range
1622 * error may occur.
1623 */
1624
1625/* FUNCTION: lrint */
1626
1627#ifndef __CPROVER_MATH_H_INCLUDED
1628#include <math.h>
1629#define __CPROVER_MATH_H_INCLUDED
1630#endif
1631
1632#ifndef __CPROVER_FENV_H_INCLUDED
1633#include <fenv.h>
1634#define __CPROVER_FENV_H_INCLUDED
1635#endif
1636
1637extern int __CPROVER_rounding_mode;
1638
1639long int lrint(double x)
1640{
1642 return (long int)rti;
1643}
1644
1645/* FUNCTION: lrintf */
1646
1647#ifndef __CPROVER_MATH_H_INCLUDED
1648#include <math.h>
1649#define __CPROVER_MATH_H_INCLUDED
1650#endif
1651
1652#ifndef __CPROVER_FENV_H_INCLUDED
1653#include <fenv.h>
1654#define __CPROVER_FENV_H_INCLUDED
1655#endif
1656
1657extern int __CPROVER_rounding_mode;
1658
1659long int lrintf(float x)
1660{
1662 return (long int)rti;
1663}
1664
1665
1666/* FUNCTION: lrintl */
1667
1668#ifndef __CPROVER_MATH_H_INCLUDED
1669#include <math.h>
1670#define __CPROVER_MATH_H_INCLUDED
1671#endif
1672
1673#ifndef __CPROVER_FENV_H_INCLUDED
1674#include <fenv.h>
1675#define __CPROVER_FENV_H_INCLUDED
1676#endif
1677
1678extern int __CPROVER_rounding_mode;
1679
1680long int lrintl(long double x)
1681{
1683 return (long int)rti;
1684}
1685
1686
1687/* FUNCTION: llrint */
1688
1689#ifndef __CPROVER_MATH_H_INCLUDED
1690#include <math.h>
1691#define __CPROVER_MATH_H_INCLUDED
1692#endif
1693
1694#ifndef __CPROVER_FENV_H_INCLUDED
1695#include <fenv.h>
1696#define __CPROVER_FENV_H_INCLUDED
1697#endif
1698
1699extern int __CPROVER_rounding_mode;
1700
1701long long int llrint(double x)
1702{
1704 return (long long int)rti;
1705}
1706
1707/* FUNCTION: llrintf */
1708
1709#ifndef __CPROVER_MATH_H_INCLUDED
1710#include <math.h>
1711#define __CPROVER_MATH_H_INCLUDED
1712#endif
1713
1714#ifndef __CPROVER_FENV_H_INCLUDED
1715#include <fenv.h>
1716#define __CPROVER_FENV_H_INCLUDED
1717#endif
1718
1719extern int __CPROVER_rounding_mode;
1720
1721long long int llrintf(float x)
1722{
1724 return (long long int)rti;
1725}
1726
1727
1728/* FUNCTION: llrintl */
1729
1730#ifndef __CPROVER_MATH_H_INCLUDED
1731#include <math.h>
1732#define __CPROVER_MATH_H_INCLUDED
1733#endif
1734
1735#ifndef __CPROVER_FENV_H_INCLUDED
1736#include <fenv.h>
1737#define __CPROVER_FENV_H_INCLUDED
1738#endif
1739
1740extern int __CPROVER_rounding_mode;
1741
1742long long int llrintl(long double x)
1743{
1745 return (long long int)rti;
1746}
1747
1748
1749/* ISO 9899:2011
1750 *
1751 * The lround and llround functions round their argument to the
1752 * nearest integer value, rounding halfway cases away from zero,
1753 * regardless of the current rounding direction. If the rounded value
1754 * is outside the range of the return type, the numeric result is
1755 * unspecified and a domain error or range error may occur.
1756 */
1757
1758/* FUNCTION: lround */
1759
1760#ifndef __CPROVER_MATH_H_INCLUDED
1761#include <math.h>
1762#define __CPROVER_MATH_H_INCLUDED
1763#endif
1764
1765#ifndef __CPROVER_FENV_H_INCLUDED
1766#include <fenv.h>
1767#define __CPROVER_FENV_H_INCLUDED
1768#endif
1769
1770long int lround(double x)
1771{
1772 double rti = __CPROVER_round_to_integrald(x, 4); // RNA
1773 return (long int)rti;
1774}
1775
1776/* FUNCTION: lroundf */
1777
1778#ifndef __CPROVER_MATH_H_INCLUDED
1779#include <math.h>
1780#define __CPROVER_MATH_H_INCLUDED
1781#endif
1782
1783#ifndef __CPROVER_FENV_H_INCLUDED
1784#include <fenv.h>
1785#define __CPROVER_FENV_H_INCLUDED
1786#endif
1787
1788long int lroundf(float x)
1789{
1790 float rti = __CPROVER_round_to_integralf(x, 4); // RNA
1791 return (long int)rti;
1792}
1793
1794
1795/* FUNCTION: lroundl */
1796
1797#ifndef __CPROVER_MATH_H_INCLUDED
1798#include <math.h>
1799#define __CPROVER_MATH_H_INCLUDED
1800#endif
1801
1802#ifndef __CPROVER_FENV_H_INCLUDED
1803#include <fenv.h>
1804#define __CPROVER_FENV_H_INCLUDED
1805#endif
1806
1807long int lroundl(long double x)
1808{
1809 long double rti = __CPROVER_round_to_integralld(x, 4); // RNA
1810 return (long int)rti;
1811}
1812
1813
1814/* FUNCTION: llround */
1815
1816#ifndef __CPROVER_MATH_H_INCLUDED
1817#include <math.h>
1818#define __CPROVER_MATH_H_INCLUDED
1819#endif
1820
1821#ifndef __CPROVER_FENV_H_INCLUDED
1822#include <fenv.h>
1823#define __CPROVER_FENV_H_INCLUDED
1824#endif
1825
1826long long int llround(double x)
1827{
1828 double rti = __CPROVER_round_to_integrald(x, 4); // RNA
1829 return (long long int)rti;
1830}
1831
1832/* FUNCTION: llroundf */
1833
1834#ifndef __CPROVER_MATH_H_INCLUDED
1835#include <math.h>
1836#define __CPROVER_MATH_H_INCLUDED
1837#endif
1838
1839#ifndef __CPROVER_FENV_H_INCLUDED
1840#include <fenv.h>
1841#define __CPROVER_FENV_H_INCLUDED
1842#endif
1843
1844long long int llroundf(float x)
1845{
1846 float rti = __CPROVER_round_to_integralf(x, 4); // RNA
1847 return (long long int)rti;
1848}
1849
1850
1851/* FUNCTION: llroundl */
1852
1853#ifndef __CPROVER_MATH_H_INCLUDED
1854#include <math.h>
1855#define __CPROVER_MATH_H_INCLUDED
1856#endif
1857
1858#ifndef __CPROVER_FENV_H_INCLUDED
1859#include <fenv.h>
1860#define __CPROVER_FENV_H_INCLUDED
1861#endif
1862
1863long long int llroundl(long double x)
1864{
1865 long double rti = __CPROVER_round_to_integralld(x, 4); // RNA
1866 return (long long int)rti;
1867}
1868
1869
1870/* ISO 9899:2011
1871 *
1872 * The modf functions break the argument value into integral and
1873 * fractional parts, each of which has the same type and sign as the
1874 * argument. They store the integral part (in floating-point format)
1875 * in the object pointed to by iptr.
1876 */
1877
1878/* FUNCTION: modf */
1879
1880#ifndef __CPROVER_MATH_H_INCLUDED
1881#include <math.h>
1882#define __CPROVER_MATH_H_INCLUDED
1883#endif
1884
1885#ifndef __CPROVER_FENV_H_INCLUDED
1886#include <fenv.h>
1887#define __CPROVER_FENV_H_INCLUDED
1888#endif
1889
1890double modf(double x, double *iptr)
1891{
1892 *iptr = __CPROVER_round_to_integrald(x, 0); // FE_TOWARDZERO
1893 return (x - *iptr);
1894}
1895
1896/* FUNCTION: modff */
1897
1898#ifndef __CPROVER_MATH_H_INCLUDED
1899#include <math.h>
1900#define __CPROVER_MATH_H_INCLUDED
1901#endif
1902
1903#ifndef __CPROVER_FENV_H_INCLUDED
1904#include <fenv.h>
1905#define __CPROVER_FENV_H_INCLUDED
1906#endif
1907
1908float modff(float x, float *iptr)
1909{
1910 *iptr = __CPROVER_round_to_integralf(x, 0); // FE_TOWARDZERO
1911 return (x - *iptr);
1912}
1913
1914
1915/* FUNCTION: modfl */
1916
1917#ifndef __CPROVER_MATH_H_INCLUDED
1918#include <math.h>
1919#define __CPROVER_MATH_H_INCLUDED
1920#endif
1921
1922#ifndef __CPROVER_FENV_H_INCLUDED
1923#include <fenv.h>
1924#define __CPROVER_FENV_H_INCLUDED
1925#endif
1926
1927long double modfl(long double x, long double *iptr)
1928{
1929 *iptr = __CPROVER_round_to_integralld(x, 0); // FE_TOWARDZERO
1930 return (x - *iptr);
1931}
1932
1933
1934
1935/* FUNCTION: __sort_of_CPROVER_remainder */
1936// TODO : Should be a real __CPROVER function to convert to SMT-LIB
1937
1938double __sort_of_CPROVER_remainder (int rounding_mode, double x, double y)
1939{
1940 if (x == 0.0 || __CPROVER_isinfd(y))
1941 return x;
1942
1943 // Extended precision helps... a bit...
1944 long double div = x/y;
1945 long double n = __CPROVER_round_to_integrald(rounding_mode, div);
1946 long double res = (-y * n) + x; // TODO : FMA would be an improvement
1947 return res;
1948}
1949
1950/* FUNCTION: __sort_of_CPROVER_remainderf */
1951// TODO : Should be a real __CPROVER function to convert to SMT-LIB
1952
1953float __sort_of_CPROVER_remainderf (int rounding_mode, float x, float y)
1954{
1955 if (x == 0.0f || __CPROVER_isinff(y))
1956 return x;
1957
1958 // Extended precision helps... a bit...
1959 long double div = x/y;
1960 long double n = __CPROVER_round_to_integralf(rounding_mode, div);
1961 long double res = (-y * n) + x; // TODO : FMA would be an improvement
1962 return res;
1963}
1964
1965/* FUNCTION: __sort_of_CPROVER_remainderl */
1966// TODO : Should be a real __CPROVER function to convert to SMT-LIB
1967
1968long double __sort_of_CPROVER_remainderl (int rounding_mode, long double x, long double y)
1969{
1970 if (x == 0.0 || __CPROVER_isinfld(y))
1971 return x;
1972
1973 // Extended precision helps... a bit...
1974 long double div = x/y;
1975 long double n = __CPROVER_round_to_integralld(rounding_mode, div);
1976 long double res = (-y * n) + x; // TODO : FMA would be an improvement
1977 return res;
1978}
1979
1980
1981
1982/* ISO 9899:2011
1983 *
1984 * The fmod functions return the value x - ny, for some
1985 * integer n such that, if y is nonzero, the result has the same sign
1986 * as x and magnitude less than the magnitude of y. If y is zero,
1987 * whether a domain error occurs or the fmod functions return zero is
1988 * implementation-defined.
1989 */
1990
1991/* FUNCTION: fmod */
1992
1993#ifndef __CPROVER_MATH_H_INCLUDED
1994#include <math.h>
1995#define __CPROVER_MATH_H_INCLUDED
1996#endif
1997
1998#ifndef __CPROVER_FENV_H_INCLUDED
1999#include <fenv.h>
2000#define __CPROVER_FENV_H_INCLUDED
2001#endif
2002
2003double fmod(double x, double y)
2004{
2005 return __CPROVER_fmod(x, y);
2006}
2007
2008/* FUNCTION: fmodf */
2009
2010#ifndef __CPROVER_MATH_H_INCLUDED
2011#include <math.h>
2012#define __CPROVER_MATH_H_INCLUDED
2013#endif
2014
2015#ifndef __CPROVER_FENV_H_INCLUDED
2016#include <fenv.h>
2017#define __CPROVER_FENV_H_INCLUDED
2018#endif
2019
2020float fmodf(float x, float y)
2021{
2022 return __CPROVER_fmodf(x, y);
2023}
2024
2025/* FUNCTION: fmodl */
2026
2027#ifndef __CPROVER_MATH_H_INCLUDED
2028#include <math.h>
2029#define __CPROVER_MATH_H_INCLUDED
2030#endif
2031
2032#ifndef __CPROVER_FENV_H_INCLUDED
2033#include <fenv.h>
2034#define __CPROVER_FENV_H_INCLUDED
2035#endif
2036
2037long double fmodl(long double x, long double y)
2038{
2039 return __CPROVER_fmodl(x, y);
2040}
2041
2042/* ISO 9899:2011
2043 *
2044 * The remainder functions compute the remainder x REM y required by
2045 * IEC 60559.239)
2046 *
2047 * 239) "When y != 0, the remainder r = x REM y is defined regardless
2048 * of the rounding mode by the mathematical relation r = x - n
2049 * y, where n is the integer nearest the exact value of x/y;
2050 * whenever | n - x/y | = 1/2, then n is even. If r = 0, its
2051 * sign shall be that of x." This definition is applicable for
2052 * all implementations.
2053 */
2054
2055/* FUNCTION: remainder */
2056
2057#ifndef __CPROVER_MATH_H_INCLUDED
2058#include <math.h>
2059#define __CPROVER_MATH_H_INCLUDED
2060#endif
2061
2062#ifndef __CPROVER_FENV_H_INCLUDED
2063#include <fenv.h>
2064#define __CPROVER_FENV_H_INCLUDED
2065#endif
2066
2067double __sort_of_CPROVER_remainder (int rounding_mode, double x, double y);
2068
2069double remainder(double x, double y) { return __sort_of_CPROVER_remainder(FE_TONEAREST, x, y); }
2070
2071
2072/* FUNCTION: remainderf */
2073
2074#ifndef __CPROVER_MATH_H_INCLUDED
2075#include <math.h>
2076#define __CPROVER_MATH_H_INCLUDED
2077#endif
2078
2079#ifndef __CPROVER_FENV_H_INCLUDED
2080#include <fenv.h>
2081#define __CPROVER_FENV_H_INCLUDED
2082#endif
2083
2084float __sort_of_CPROVER_remainderf (int rounding_mode, float x, float y);
2085
2086float remainderf(float x, float y) { return __sort_of_CPROVER_remainderf(FE_TONEAREST, x, y); }
2087
2088
2089/* FUNCTION: remainderl */
2090
2091#ifndef __CPROVER_MATH_H_INCLUDED
2092#include <math.h>
2093#define __CPROVER_MATH_H_INCLUDED
2094#endif
2095
2096#ifndef __CPROVER_FENV_H_INCLUDED
2097#include <fenv.h>
2098#define __CPROVER_FENV_H_INCLUDED
2099#endif
2100
2101long double __sort_of_CPROVER_remainderl (int rounding_mode, long double x, long double y);
2102
2103long double remainderl(long double x, long double y) { return __sort_of_CPROVER_remainderl(FE_TONEAREST, x, y); }
2104
2105
2106
2107
2108/* ISO 9899:2011
2109 * The copysign functions produce a value with the magnitude of x and
2110 * the sign of y. They produce a NaN (with the sign of y) if x is a
2111 * NaN. On implementations that represent a signed zero but do not
2112 * treat negative zero consistently in arithmetic operations, the
2113 * copysign functions regard the sign of zero as positive.
2114 */
2115
2116/* FUNCTION: copysign */
2117
2118#ifndef __CPROVER_MATH_H_INCLUDED
2119#include <math.h>
2120#define __CPROVER_MATH_H_INCLUDED
2121#endif
2122
2123double fabs (double d);
2124
2125double copysign(double x, double y)
2126{
2127 double abs = fabs(x);
2128 return (signbit(y)) ? -abs : abs;
2129}
2130
2131/* FUNCTION: copysignf */
2132
2133#ifndef __CPROVER_MATH_H_INCLUDED
2134#include <math.h>
2135#define __CPROVER_MATH_H_INCLUDED
2136#endif
2137
2138float fabsf (float d);
2139
2140float copysignf(float x, float y)
2141{
2142 float abs = fabsf(x);
2143 return (signbit(y)) ? -abs : abs;
2144}
2145
2146/* FUNCTION: copysignl */
2147
2148#ifndef __CPROVER_MATH_H_INCLUDED
2149#include <math.h>
2150#define __CPROVER_MATH_H_INCLUDED
2151#endif
2152
2153long double fabsl (long double d);
2154
2155long double copysignl(long double x, long double y)
2156{
2157 long double abs = fabsl(x);
2158 return (signbit(y)) ? -abs : abs;
2159}
2160
2161/* FUNCTION: exp2 */
2162
2163#ifndef __CPROVER_MATH_H_INCLUDED
2164# include <math.h>
2165# define __CPROVER_MATH_H_INCLUDED
2166#endif
2167
2168double exp2(double x)
2169{
2170 return pow(2.0, x);
2171}
2172
2173/* FUNCTION: exp2f */
2174
2175#ifndef __CPROVER_MATH_H_INCLUDED
2176# include <math.h>
2177# define __CPROVER_MATH_H_INCLUDED
2178#endif
2179
2180float exp2f(float x)
2181{
2182 return powf(2.0f, x);
2183}
2184
2185/* FUNCTION: exp2l */
2186
2187#ifndef __CPROVER_MATH_H_INCLUDED
2188# include <math.h>
2189# define __CPROVER_MATH_H_INCLUDED
2190#endif
2191
2192long double exp2l(long double x)
2193{
2194 return powl(2.0l, x);
2195}
2196
2197/* FUNCTION: exp */
2198
2199#ifndef __CPROVER_MATH_H_INCLUDED
2200# ifdef _WIN32
2201# define _USE_MATH_DEFINES
2202# endif
2203# include <math.h>
2204# define __CPROVER_MATH_H_INCLUDED
2205#endif
2206
2207#ifndef __CPROVER_STDINT_H_INCLUDED
2208# include <stdint.h>
2209# define __CPROVER_STDINT_H_INCLUDED
2210#endif
2211
2212#ifndef __CPROVER_ERRNO_H_INCLUDED
2213# include <errno.h>
2214# define __CPROVER_ERRNO_H_INCLUDED
2215#endif
2216
2218
2219double exp(double x)
2220{
2222 return x;
2223 else if(__CPROVER_isinfd(x) && __CPROVER_signd(x))
2224 return +0.0;
2225 // underflow/overflow when the result is not representable in 11 exponent bits
2226 else if(x < -1024.0 * M_LN2)
2227 {
2228 errno = ERANGE;
2229 return 0.0;
2230 }
2231 else if(x > 1024.0 * M_LN2)
2232 {
2233 errno = ERANGE;
2234#pragma CPROVER check push
2235#pragma CPROVER check disable "float-overflow"
2236 return HUGE_VAL;
2237#pragma CPROVER check pop
2238 }
2239
2240 // Nicol N. Schraudolph: A Fast, Compact Approximation of the Exponential
2241 // Function. Neural Computation 11(4), 1999
2242 // https://schraudolph.org/pubs/Schraudolph99.pdf
2243 // 20 is 32 - 1 sign bit - 11 exponent bits
2244 int32_t bias = (1 << 20) * ((1 << 10) - 1);
2245 int32_t exp_a_x = (int32_t)(x / M_LN2 * (double)(1 << 20)) + bias;
2246 // EXP'C controls the approximation; the paper suggests 60801, but -1 yields
2247 // an upper bound and 90253 a lower bound, and we pick a value in between.
2248 int32_t lower = exp_a_x - 90253;
2249 int32_t upper = exp_a_x + 1;
2251 __CPROVER_assume(result >= lower);
2252 __CPROVER_assume(result <= upper);
2253
2254#ifndef _MSC_VER
2255 _Static_assert
2256#else
2257 static_assert
2258#endif
2259 (sizeof(double) == 2 * sizeof(int32_t),
2260 "bit width of double is 2x bit width of int32_t");
2261 union U
2262 {
2263 double d;
2264 int32_t i[2];
2265 };
2266#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2267 union U u = {.i = {0, result}};
2268#else
2269 union U u = {.i = {result, 0}};
2270#endif
2271 return u.d;
2272}
2273
2274/* FUNCTION: expf */
2275
2276#ifndef __CPROVER_MATH_H_INCLUDED
2277# ifdef _WIN32
2278# define _USE_MATH_DEFINES
2279# endif
2280# include <math.h>
2281# define __CPROVER_MATH_H_INCLUDED
2282#endif
2283
2284#ifndef __CPROVER_STDINT_H_INCLUDED
2285# include <stdint.h>
2286# define __CPROVER_STDINT_H_INCLUDED
2287#endif
2288
2289#ifndef __CPROVER_ERRNO_H_INCLUDED
2290# include <errno.h>
2291# define __CPROVER_ERRNO_H_INCLUDED
2292#endif
2293
2295
2296float expf(float x)
2297{
2299 return x;
2300 else if(__CPROVER_isinff(x) && __CPROVER_signf(x))
2301 return +0.0f;
2302 // underflow/overflow when the result is not representable in 8 exponent bits
2303 else if(x < -128.0f * (float)M_LN2)
2304 {
2305 errno = ERANGE;
2306 return 0.0f;
2307 }
2308 else if(x > 128.0f * (float)M_LN2)
2309 {
2310 errno = ERANGE;
2311#pragma CPROVER check push
2312#pragma CPROVER check disable "float-overflow"
2313 return HUGE_VALF;
2314#pragma CPROVER check pop
2315 }
2316
2317 // 23 is 32 - 1 sign bit - 8 exponent bits
2318 int32_t bias = (1 << 23) * ((1 << 7) - 1);
2319 int32_t exp_a_x = (int32_t)(x / (float)M_LN2 * (float)(1 << 23)) + bias;
2320 // 722019 is 2^23 * [1 - [ln(ln(2)) + 1] / ln(2)] rounded up -- see Appendix
2321 // of Schraudolph's paper
2322 int32_t lower = exp_a_x - 722019;
2323 int32_t upper = exp_a_x + 1;
2325 __CPROVER_assume(result >= lower);
2326 __CPROVER_assume(result <= upper);
2327
2328#ifndef _MSC_VER
2329 _Static_assert
2330#else
2331 static_assert
2332#endif
2333 (sizeof(float) == sizeof(int32_t),
2334 "bit width of float and int32_t should match");
2335 union U
2336 {
2337 float f;
2338 int32_t i;
2339 };
2340 union U u = {.i = result};
2341 return u.f;
2342}
2343
2344/* FUNCTION: expl */
2345
2346#ifndef __CPROVER_MATH_H_INCLUDED
2347# ifdef _WIN32
2348# define _USE_MATH_DEFINES
2349# endif
2350# include <math.h>
2351# define __CPROVER_MATH_H_INCLUDED
2352#endif
2353
2354#ifndef __CPROVER_FLOAT_H_INCLUDED
2355# include <float.h>
2356# define __CPROVER_FLOAT_H_INCLUDED
2357#endif
2358
2359#ifndef __CPROVER_STDINT_H_INCLUDED
2360# include <stdint.h>
2361# define __CPROVER_STDINT_H_INCLUDED
2362#endif
2363
2364#ifndef __CPROVER_ERRNO_H_INCLUDED
2365# include <errno.h>
2366# define __CPROVER_ERRNO_H_INCLUDED
2367#endif
2368
2370
2371long double expl(long double x)
2372{
2374 return x;
2376 return +0.0l;
2377
2378#if LDBL_MAX_EXP == DBL_MAX_EXP
2379 return exp(x);
2380#else
2381 // underflow/overflow when the result is not representable in 15 exponent bits
2382 if(x < -16384.0l * M_LN2)
2383 {
2384 errno = ERANGE;
2385 return 0.0l;
2386 }
2387 else if(x > 16384.0l * M_LN2)
2388 {
2389 errno = ERANGE;
2390# pragma CPROVER check push
2391# pragma CPROVER check disable "float-overflow"
2392 return HUGE_VALL;
2393# pragma CPROVER check pop
2394 }
2395 // 16 is 32 - 1 sign bit - 15 exponent bits
2396 int32_t bias = (1 << 16) * ((1 << 14) - 1);
2397 int32_t exp_a_x = (int32_t)(x / M_LN2 * (long double)(1 << 16)) + bias;
2398 // 5641 is 2^16 * [1 - [ln(ln(2)) + 1] / ln(2)] rounded up -- see Appendix
2399 // of Schraudolph's paper
2400 int32_t lower = exp_a_x - 5641;
2401 int32_t upper = exp_a_x + 1;
2403 __CPROVER_assume(result >= lower);
2404 __CPROVER_assume(result <= upper);
2405
2406# ifndef _MSC_VER
2407 _Static_assert
2408# else
2409 static_assert
2410# endif
2411 (sizeof(long double) % sizeof(int32_t) == 0,
2412 "bit width of long double is a multiple of bit width of int32_t");
2413 union
2414 {
2415 long double l;
2416 int32_t i[sizeof(long double) / sizeof(int32_t)];
2417 } u = {.i = {0}};
2418# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2419 u.i[sizeof(long double) / sizeof(int32_t) - 1] = result;
2420# else
2421 u.i[0] = result;
2422# endif
2423 return u.l;
2424#endif
2425}
2426
2427/* FUNCTION: log */
2428
2429#ifndef __CPROVER_MATH_H_INCLUDED
2430# ifdef _WIN32
2431# define _USE_MATH_DEFINES
2432# endif
2433# include <math.h>
2434# define __CPROVER_MATH_H_INCLUDED
2435#endif
2436
2437#ifndef __CPROVER_STDINT_H_INCLUDED
2438# include <stdint.h>
2439# define __CPROVER_STDINT_H_INCLUDED
2440#endif
2441
2442#ifndef __CPROVER_ERRNO_H_INCLUDED
2443# include <errno.h>
2444# define __CPROVER_ERRNO_H_INCLUDED
2445#endif
2446
2448
2449double log(double x)
2450{
2452 return x;
2453 else if(x == 1.0)
2454 return +0.0;
2455 else if(fpclassify(x) == FP_ZERO)
2456 {
2457 errno = ERANGE;
2458#pragma CPROVER check push
2459#pragma CPROVER check disable "float-overflow"
2460 return -HUGE_VAL;
2461#pragma CPROVER check pop
2462 }
2463 else if(__CPROVER_signd(x))
2464 {
2465 errno = EDOM;
2466#pragma CPROVER check push
2467#pragma CPROVER check disable "float-div-by-zero"
2468 return 0.0 / 0.0;
2469#pragma CPROVER check pop
2470 }
2471
2472#ifndef _MSC_VER
2473 _Static_assert
2474#else
2475 static_assert
2476#endif
2477 (sizeof(double) == 2 * sizeof(int32_t),
2478 "bit width of double is 2x bit width of int32_t");
2479 // https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
2480 union
2481 {
2482 double d;
2483 int32_t i[2];
2484 } u = {x};
2485 int32_t bias = (1 << 20) * ((1 << 10) - 1);
2487 __CPROVER_assume(exp_c >= -90253 && exp_c <= 1);
2488#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2489 return ((double)u.i[1] - (double)(bias + exp_c)) * M_LN2 / (double)(1 << 20);
2490#else
2491 return ((double)u.i[0] - (double)(bias + exp_c)) * M_LN2 / (double)(1 << 20);
2492#endif
2493}
2494
2495/* FUNCTION: logf */
2496
2497#ifndef __CPROVER_MATH_H_INCLUDED
2498# ifdef _WIN32
2499# define _USE_MATH_DEFINES
2500# endif
2501# include <math.h>
2502# define __CPROVER_MATH_H_INCLUDED
2503#endif
2504
2505#ifndef __CPROVER_STDINT_H_INCLUDED
2506# include <stdint.h>
2507# define __CPROVER_STDINT_H_INCLUDED
2508#endif
2509
2510#ifndef __CPROVER_ERRNO_H_INCLUDED
2511# include <errno.h>
2512# define __CPROVER_ERRNO_H_INCLUDED
2513#endif
2514
2516
2517float logf(float x)
2518{
2520 return x;
2521 else if(x == 1.0f)
2522 return +0.0f;
2523 else if(fpclassify(x) == FP_ZERO)
2524 {
2525 errno = ERANGE;
2526#pragma CPROVER check push
2527#pragma CPROVER check disable "float-overflow"
2528 return -HUGE_VALF;
2529#pragma CPROVER check pop
2530 }
2531 else if(__CPROVER_signf(x))
2532 {
2533 errno = EDOM;
2534#pragma CPROVER check push
2535#pragma CPROVER check disable "float-div-by-zero"
2536 return 0.0f / 0.0f;
2537#pragma CPROVER check pop
2538 }
2539
2540#ifndef _MSC_VER
2541 _Static_assert
2542#else
2543 static_assert
2544#endif
2545 (sizeof(float) == sizeof(int32_t),
2546 "bit width of float and int32_t should match");
2547 // https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
2548 union
2549 {
2550 float f;
2551 int32_t i;
2552 } u = {x};
2553 int32_t bias = (1 << 23) * ((1 << 7) - 1);
2555 __CPROVER_assume(exp_c >= -722019 && exp_c <= 1);
2556 return ((float)u.i - (float)(bias + exp_c)) * (float)M_LN2 / (float)(1 << 23);
2557}
2558
2559/* FUNCTION: logl */
2560
2561#ifndef __CPROVER_MATH_H_INCLUDED
2562# ifdef _WIN32
2563# define _USE_MATH_DEFINES
2564# endif
2565# include <math.h>
2566# define __CPROVER_MATH_H_INCLUDED
2567#endif
2568
2569#ifndef __CPROVER_STDINT_H_INCLUDED
2570# include <stdint.h>
2571# define __CPROVER_STDINT_H_INCLUDED
2572#endif
2573
2574#ifndef __CPROVER_ERRNO_H_INCLUDED
2575# include <errno.h>
2576# define __CPROVER_ERRNO_H_INCLUDED
2577#endif
2578
2579#ifndef __CPROVER_FLOAT_H_INCLUDED
2580# include <float.h>
2581# define __CPROVER_FLOAT_H_INCLUDED
2582#endif
2583
2585
2586long double logl(long double x)
2587{
2589 return x;
2590 else if(x == 1.0l)
2591 return +0.0l;
2592 else if(fpclassify(x) == FP_ZERO)
2593 {
2594 errno = ERANGE;
2595#pragma CPROVER check push
2596#pragma CPROVER check disable "float-overflow"
2597 return -HUGE_VALL;
2598#pragma CPROVER check pop
2599 }
2600 else if(__CPROVER_signld(x))
2601 {
2602 errno = EDOM;
2603#pragma CPROVER check push
2604#pragma CPROVER check disable "float-div-by-zero"
2605 return 0.0l / 0.0l;
2606#pragma CPROVER check pop
2607 }
2608
2609#if LDBL_MAX_EXP == DBL_MAX_EXP
2610 return log(x);
2611#else
2612# ifndef _MSC_VER
2613 _Static_assert
2614# else
2615 static_assert
2616# endif
2617 (sizeof(long double) % sizeof(int32_t) == 0,
2618 "bit width of long double is a multiple of bit width of int32_t");
2619 union
2620 {
2621 long double l;
2622 int32_t i[sizeof(long double) / sizeof(int32_t)];
2623 } u = {x};
2624 int32_t bias = (1 << 16) * ((1 << 14) - 1);
2626 __CPROVER_assume(exp_c >= -5641 && exp_c <= 1);
2627# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2628 return ((long double)u.i[sizeof(long double) / sizeof(int32_t) - 1] -
2629 (long double)(bias + exp_c)) *
2630 M_LN2 / (long double)(1 << 16);
2631# else
2632 return ((long double)u.i[0] - (long double)(bias + exp_c)) * M_LN2 /
2633 (long double)(1 << 16);
2634# endif
2635#endif
2636}
2637
2638/* FUNCTION: log2 */
2639
2640#ifndef __CPROVER_MATH_H_INCLUDED
2641# ifdef _WIN32
2642# define _USE_MATH_DEFINES
2643# endif
2644# include <math.h>
2645# define __CPROVER_MATH_H_INCLUDED
2646#endif
2647
2648#ifndef __CPROVER_STDINT_H_INCLUDED
2649# include <stdint.h>
2650# define __CPROVER_STDINT_H_INCLUDED
2651#endif
2652
2653#ifndef __CPROVER_ERRNO_H_INCLUDED
2654# include <errno.h>
2655# define __CPROVER_ERRNO_H_INCLUDED
2656#endif
2657
2659
2660double log2(double x)
2661{
2663 return x;
2664 else if(x == 1.0)
2665 return +0.0;
2666 else if(fpclassify(x) == FP_ZERO)
2667 {
2668 errno = ERANGE;
2669#pragma CPROVER check push
2670#pragma CPROVER check disable "float-overflow"
2671 return -HUGE_VAL;
2672#pragma CPROVER check pop
2673 }
2674 else if(__CPROVER_signd(x))
2675 {
2676 errno = EDOM;
2677#pragma CPROVER check push
2678#pragma CPROVER check disable "float-div-by-zero"
2679 return 0.0 / 0.0;
2680#pragma CPROVER check pop
2681 }
2682
2683#ifndef _MSC_VER
2684 _Static_assert
2685#else
2686 static_assert
2687#endif
2688 (sizeof(double) == 2 * sizeof(int32_t),
2689 "bit width of double is 2x bit width of int32_t");
2690 union
2691 {
2692 double d;
2693 int32_t i[2];
2694 } u = {x};
2695 int32_t bias = (1 << 20) * ((1 << 10) - 1);
2697 __CPROVER_assume(exp_c >= -90253 && exp_c <= 1);
2698#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2699 return ((double)u.i[1] - (double)(bias + exp_c)) / (double)(1 << 20);
2700#else
2701 return ((double)u.i[0] - (double)(bias + exp_c)) / (double)(1 << 20);
2702#endif
2703}
2704
2705/* FUNCTION: log2f */
2706
2707#ifndef __CPROVER_MATH_H_INCLUDED
2708# ifdef _WIN32
2709# define _USE_MATH_DEFINES
2710# endif
2711# include <math.h>
2712# define __CPROVER_MATH_H_INCLUDED
2713#endif
2714
2715#ifndef __CPROVER_STDINT_H_INCLUDED
2716# include <stdint.h>
2717# define __CPROVER_STDINT_H_INCLUDED
2718#endif
2719
2720#ifndef __CPROVER_ERRNO_H_INCLUDED
2721# include <errno.h>
2722# define __CPROVER_ERRNO_H_INCLUDED
2723#endif
2724
2726
2727float log2f(float x)
2728{
2730 return x;
2731 else if(x == 1.0f)
2732 return +0.0f;
2733 else if(fpclassify(x) == FP_ZERO)
2734 {
2735 errno = ERANGE;
2736#pragma CPROVER check push
2737#pragma CPROVER check disable "float-overflow"
2738 return -HUGE_VALF;
2739#pragma CPROVER check pop
2740 }
2741 else if(__CPROVER_signf(x))
2742 {
2743 errno = EDOM;
2744#pragma CPROVER check push
2745#pragma CPROVER check disable "float-div-by-zero"
2746 return 0.0f / 0.0f;
2747#pragma CPROVER check pop
2748 }
2749
2750#ifndef _MSC_VER
2751 _Static_assert
2752#else
2753 static_assert
2754#endif
2755 (sizeof(float) == sizeof(int32_t),
2756 "bit width of float and int32_t should match");
2757 union
2758 {
2759 float f;
2760 int32_t i;
2761 } u = {x};
2762 int32_t bias = (1 << 23) * ((1 << 7) - 1);
2764 __CPROVER_assume(exp_c >= -722019 && exp_c <= 1);
2765 return ((float)u.i - (float)(bias + exp_c)) / (float)(1 << 23);
2766}
2767
2768/* FUNCTION: log2l */
2769
2770#ifndef __CPROVER_MATH_H_INCLUDED
2771# ifdef _WIN32
2772# define _USE_MATH_DEFINES
2773# endif
2774# include <math.h>
2775# define __CPROVER_MATH_H_INCLUDED
2776#endif
2777
2778#ifndef __CPROVER_STDINT_H_INCLUDED
2779# include <stdint.h>
2780# define __CPROVER_STDINT_H_INCLUDED
2781#endif
2782
2783#ifndef __CPROVER_ERRNO_H_INCLUDED
2784# include <errno.h>
2785# define __CPROVER_ERRNO_H_INCLUDED
2786#endif
2787
2788#ifndef __CPROVER_FLOAT_H_INCLUDED
2789# include <float.h>
2790# define __CPROVER_FLOAT_H_INCLUDED
2791#endif
2792
2794
2795long double log2l(long double x)
2796{
2798 return x;
2799 else if(x == 1.0l)
2800 return +0.0l;
2801 else if(fpclassify(x) == FP_ZERO)
2802 {
2803 errno = ERANGE;
2804#pragma CPROVER check push
2805#pragma CPROVER check disable "float-overflow"
2806 return -HUGE_VALL;
2807#pragma CPROVER check pop
2808 }
2809 else if(__CPROVER_signld(x))
2810 {
2811 errno = EDOM;
2812#pragma CPROVER check push
2813#pragma CPROVER check disable "float-div-by-zero"
2814 return 0.0l / 0.0l;
2815#pragma CPROVER check pop
2816 }
2817
2818#if LDBL_MAX_EXP == DBL_MAX_EXP
2819 return log2(x);
2820#else
2821# ifndef _MSC_VER
2822 _Static_assert
2823# else
2824 static_assert
2825# endif
2826 (sizeof(long double) % sizeof(int32_t) == 0,
2827 "bit width of long double is a multiple of bit width of int32_t");
2828 union
2829 {
2830 long double l;
2831 int32_t i[sizeof(long double) / sizeof(int32_t)];
2832 } u = {x};
2833 int32_t bias = (1 << 16) * ((1 << 14) - 1);
2835 __CPROVER_assume(exp_c >= -5641 && exp_c <= 1);
2836# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2837 return ((long double)u.i[sizeof(long double) / sizeof(int32_t) - 1] -
2838 (long double)(bias + exp_c)) /
2839 (long double)(1 << 16);
2840# else
2841 return ((long double)u.i[0] - (long double)(bias + exp_c)) /
2842 (long double)(1 << 16);
2843# endif
2844#endif
2845}
2846
2847/* FUNCTION: log10 */
2848
2849#ifndef __CPROVER_MATH_H_INCLUDED
2850# ifdef _WIN32
2851# define _USE_MATH_DEFINES
2852# endif
2853# include <math.h>
2854# define __CPROVER_MATH_H_INCLUDED
2855#endif
2856
2857#ifndef __CPROVER_STDINT_H_INCLUDED
2858# include <stdint.h>
2859# define __CPROVER_STDINT_H_INCLUDED
2860#endif
2861
2862#ifndef __CPROVER_ERRNO_H_INCLUDED
2863# include <errno.h>
2864# define __CPROVER_ERRNO_H_INCLUDED
2865#endif
2866
2868
2869double log10(double x)
2870{
2872 return x;
2873 else if(x == 1.0)
2874 return +0.0;
2875 else if(fpclassify(x) == FP_ZERO)
2876 {
2877 errno = ERANGE;
2878#pragma CPROVER check push
2879#pragma CPROVER check disable "float-overflow"
2880 return -HUGE_VAL;
2881#pragma CPROVER check pop
2882 }
2883 else if(__CPROVER_signd(x))
2884 {
2885 errno = EDOM;
2886#pragma CPROVER check push
2887#pragma CPROVER check disable "float-div-by-zero"
2888 return 0.0 / 0.0;
2889#pragma CPROVER check pop
2890 }
2891
2892#ifndef _MSC_VER
2893 _Static_assert
2894#else
2895 static_assert
2896#endif
2897 (sizeof(double) == 2 * sizeof(int32_t),
2898 "bit width of double is 2x bit width of int32_t");
2899 // https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
2900 union
2901 {
2902 double d;
2903 int32_t i[2];
2904 } u = {x};
2905 int32_t bias = (1 << 20) * ((1 << 10) - 1);
2907 __CPROVER_assume(exp_c >= -90253 && exp_c <= 1);
2908#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2909 return ((double)u.i[1] - (double)(bias + exp_c)) * (M_LN2 / M_LN10) /
2910 (double)(1 << 20);
2911#else
2912 return ((double)u.i[0] - (double)(bias + exp_c)) * (M_LN2 / M_LN10) /
2913 (double)(1 << 20);
2914#endif
2915}
2916
2917/* FUNCTION: log10f */
2918
2919#ifndef __CPROVER_MATH_H_INCLUDED
2920# ifdef _WIN32
2921# define _USE_MATH_DEFINES
2922# endif
2923# include <math.h>
2924# define __CPROVER_MATH_H_INCLUDED
2925#endif
2926
2927#ifndef __CPROVER_STDINT_H_INCLUDED
2928# include <stdint.h>
2929# define __CPROVER_STDINT_H_INCLUDED
2930#endif
2931
2932#ifndef __CPROVER_ERRNO_H_INCLUDED
2933# include <errno.h>
2934# define __CPROVER_ERRNO_H_INCLUDED
2935#endif
2936
2938
2939float log10f(float x)
2940{
2942 return x;
2943 else if(x == 1.0f)
2944 return +0.0f;
2945 else if(fpclassify(x) == FP_ZERO)
2946 {
2947 errno = ERANGE;
2948#pragma CPROVER check push
2949#pragma CPROVER check disable "float-overflow"
2950 return -HUGE_VALF;
2951#pragma CPROVER check pop
2952 }
2953 else if(__CPROVER_signf(x))
2954 {
2955 errno = EDOM;
2956#pragma CPROVER check push
2957#pragma CPROVER check disable "float-div-by-zero"
2958 return 0.0f / 0.0f;
2959#pragma CPROVER check pop
2960 }
2961
2962#ifndef _MSC_VER
2963 _Static_assert
2964#else
2965 static_assert
2966#endif
2967 (sizeof(float) == sizeof(int32_t),
2968 "bit width of float and int32_t should match");
2969 // https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
2970 union
2971 {
2972 float f;
2973 int32_t i;
2974 } u = {x};
2975 int32_t bias = (1 << 23) * ((1 << 7) - 1);
2977 __CPROVER_assume(exp_c >= -722019 && exp_c <= 1);
2978 return ((float)u.i - (float)(bias + exp_c)) * (float)(M_LN2 / M_LN10) /
2979 (float)(1 << 23);
2980}
2981
2982/* FUNCTION: log10l */
2983
2984#ifndef __CPROVER_MATH_H_INCLUDED
2985# ifdef _WIN32
2986# define _USE_MATH_DEFINES
2987# endif
2988# include <math.h>
2989# define __CPROVER_MATH_H_INCLUDED
2990#endif
2991
2992#ifndef __CPROVER_STDINT_H_INCLUDED
2993# include <stdint.h>
2994# define __CPROVER_STDINT_H_INCLUDED
2995#endif
2996
2997#ifndef __CPROVER_ERRNO_H_INCLUDED
2998# include <errno.h>
2999# define __CPROVER_ERRNO_H_INCLUDED
3000#endif
3001
3002#ifndef __CPROVER_FLOAT_H_INCLUDED
3003# include <float.h>
3004# define __CPROVER_FLOAT_H_INCLUDED
3005#endif
3006
3008
3009long double log10l(long double x)
3010{
3012 return x;
3013 else if(x == 1.0l)
3014 return +0.0l;
3015 else if(fpclassify(x) == FP_ZERO)
3016 {
3017 errno = ERANGE;
3018#pragma CPROVER check push
3019#pragma CPROVER check disable "float-overflow"
3020 return -HUGE_VALL;
3021#pragma CPROVER check pop
3022 }
3023 else if(__CPROVER_signld(x))
3024 {
3025 errno = EDOM;
3026#pragma CPROVER check push
3027#pragma CPROVER check disable "float-div-by-zero"
3028 return 0.0l / 0.0l;
3029#pragma CPROVER check pop
3030 }
3031
3032#if LDBL_MAX_EXP == DBL_MAX_EXP
3033 return log10(x);
3034#else
3035# ifndef _MSC_VER
3036 _Static_assert
3037# else
3038 static_assert
3039# endif
3040 (sizeof(long double) % sizeof(int32_t) == 0,
3041 "bit width of long double is a multiple of bit width of int32_t");
3042 union
3043 {
3044 long double l;
3045 int32_t i[sizeof(long double) / sizeof(int32_t)];
3046 } u = {x};
3047 int32_t bias = (1 << 16) * ((1 << 14) - 1);
3049 __CPROVER_assume(exp_c >= -5641 && exp_c <= 1);
3050# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3051 return ((long double)u.i[sizeof(long double) / sizeof(int32_t) - 1] -
3052 (long double)(bias + exp_c)) *
3053 (M_LN2 / M_LN10) / (long double)(1 << 16);
3054# else
3055 return ((long double)u.i[0] - (long double)(bias + exp_c)) *
3056 (M_LN2 / M_LN10) / (long double)(1 << 16);
3057# endif
3058#endif
3059}
3060
3061/* FUNCTION: pow */
3062
3063#ifndef __CPROVER_MATH_H_INCLUDED
3064# include <math.h>
3065# define __CPROVER_MATH_H_INCLUDED
3066#endif
3067
3068#ifndef __CPROVER_STDINT_H_INCLUDED
3069# include <stdint.h>
3070# define __CPROVER_STDINT_H_INCLUDED
3071#endif
3072
3073#ifndef __CPROVER_ERRNO_H_INCLUDED
3074# include <errno.h>
3075# define __CPROVER_ERRNO_H_INCLUDED
3076#endif
3077
3079
3080double __builtin_inf(void);
3081
3082double pow(double x, double y)
3083{
3084 // see man pow (https://linux.die.net/man/3/pow)
3085 if(
3087 nearbyint(y) != y)
3088 {
3089 errno = EDOM;
3090#pragma CPROVER check push
3091#pragma CPROVER check disable "float-div-by-zero"
3092 return 0.0 / 0.0;
3093#pragma CPROVER check pop
3094 }
3095 else if(x == 1.0)
3096 return 1.0;
3097 else if(fpclassify(y) == FP_ZERO)
3098 return 1.0;
3099 else if(fpclassify(x) == FP_ZERO && !__CPROVER_signd(y))
3100 {
3101 if(nearbyint(y) == y && fabs(fmod(y, 2.0)) == 1.0)
3102 return x;
3103 else
3104 return +0.0;
3105 }
3106 else if(isinf(y))
3107 {
3108 // x == 1.0 and y-is-zero caught above
3109 if(x == -1.0)
3110 return 1.0;
3111 else if(__CPROVER_signd(y))
3112 {
3113 if(fabs(x) < 1.0)
3114 return __builtin_inf();
3115 else
3116 return +0.0;
3117 }
3118 else
3119 {
3120 if(fabs(x) < 1.0)
3121 return +0.0;
3122 else
3123 return __builtin_inf();
3124 }
3125 }
3126 else if(isinf(x) && __CPROVER_signd(x))
3127 {
3128 if(__CPROVER_signd(y))
3129 {
3130 if(nearbyint(y) == y && fabs(fmod(y, 2.0)) == 1.0)
3131 return -0.0;
3132 else
3133 return +0.0;
3134 }
3135 else
3136 {
3137 if(nearbyint(y) == y && fabs(fmod(y, 2.0)) == 1.0)
3138 return -__builtin_inf();
3139 else
3140 return __builtin_inf();
3141 }
3142 }
3143 else if(isinf(x) && !__CPROVER_signd(x))
3144 {
3145 if(__CPROVER_signd(y))
3146 return +0.0;
3147 else
3148 return __builtin_inf();
3149 }
3150 else if(fpclassify(x) == FP_ZERO && __CPROVER_signd(y))
3151 {
3152 errno = ERANGE;
3153#pragma CPROVER check push
3154#pragma CPROVER check disable "float-overflow"
3155 if(__CPROVER_signd(x) && nearbyint(y) == y && fabs(fmod(y, 2.0)) == 1.0)
3156 return -HUGE_VAL;
3157 else
3158 return HUGE_VAL;
3159#pragma CPROVER check pop
3160 }
3161 else if(isnan(x) || isnan(y))
3162#pragma CPROVER check push
3163#pragma CPROVER check disable "float-div-by-zero"
3164 return 0.0 / 0.0;
3165#pragma CPROVER check pop
3166
3167#ifndef _MSC_VER
3168 _Static_assert
3169#else
3170 static_assert
3171#endif
3172 (sizeof(double) == 2 * sizeof(int32_t),
3173 "bit width of double is 2x bit width of int32_t");
3174 // https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
3175 union
3176 {
3177 double d;
3178 int32_t i[2];
3179 } u = {x};
3180 int32_t bias = (1 << 20) * ((1 << 10) - 1);
3182 __CPROVER_assume(exp_c >= -90253 && exp_c <= 1);
3183#pragma CPROVER check push
3184#pragma CPROVER check disable "signed-overflow"
3185#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3186 double mult_result = y * (double)(u.i[1] - (bias + exp_c));
3187#else
3188 double mult_result = y * (double)(u.i[0] - (bias + exp_c));
3189#endif
3190#pragma CPROVER check pop
3191 if(fabs(mult_result) > (double)(1 << 30))
3192 {
3193 errno = ERANGE;
3194#pragma CPROVER check push
3195#pragma CPROVER check disable "float-overflow"
3196 return y > 0.0 ? HUGE_VAL : 0.0;
3197#pragma CPROVER check pop
3198 }
3199#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3200 u.i[1] = (int32_t)mult_result + (bias + exp_c);
3201 u.i[0] = 0;
3202#else
3203 u.i[0] = (int32_t)mult_result + (bias + exp_c);
3204 u.i[1] = 0;
3205#endif
3206 return u.d;
3207}
3208
3209/* FUNCTION: powf */
3210
3211#ifndef __CPROVER_MATH_H_INCLUDED
3212# include <math.h>
3213# define __CPROVER_MATH_H_INCLUDED
3214#endif
3215
3216#ifndef __CPROVER_STDINT_H_INCLUDED
3217# include <stdint.h>
3218# define __CPROVER_STDINT_H_INCLUDED
3219#endif
3220
3221#ifndef __CPROVER_ERRNO_H_INCLUDED
3222# include <errno.h>
3223# define __CPROVER_ERRNO_H_INCLUDED
3224#endif
3225
3227
3228float __builtin_inff(void);
3229
3230float powf(float x, float y)
3231{
3232 // see man pow (https://linux.die.net/man/3/pow)
3233 if(
3235 nearbyintf(y) != y)
3236 {
3237 errno = EDOM;
3238#pragma CPROVER check push
3239#pragma CPROVER check disable "float-div-by-zero"
3240 return 0.0f / 0.0f;
3241#pragma CPROVER check pop
3242 }
3243 else if(x == 1.0f)
3244 return 1.0f;
3245 else if(fpclassify(y) == FP_ZERO)
3246 return 1.0f;
3247 else if(fpclassify(x) == FP_ZERO && !__CPROVER_signf(y))
3248 {
3249 if(nearbyintf(y) == y && fabsf(fmodf(y, 2.0f)) == 1.0f)
3250 return x;
3251 else
3252 return +0.0f;
3253 }
3254 else if(isinff(y))
3255 {
3256 // x == 1.0f and y-is-zero caught above
3257 if(x == -1.0f)
3258 return 1.0f;
3259 else if(__CPROVER_signf(y))
3260 {
3261 if(fabsf(x) < 1.0f)
3262 return __builtin_inff();
3263 else
3264 return +0.0f;
3265 }
3266 else
3267 {
3268 if(fabsf(x) < 1.0f)
3269 return +0.0f;
3270 else
3271 return __builtin_inff();
3272 }
3273 }
3274 else if(isinff(x) && __CPROVER_signf(x))
3275 {
3276 if(__CPROVER_signf(y))
3277 {
3278 if(nearbyintf(y) == y && fabsf(fmodf(y, 2.0f)) == 1.0f)
3279 return -0.0f;
3280 else
3281 return +0.0f;
3282 }
3283 else
3284 {
3285 if(nearbyintf(y) == y && fabsf(fmodf(y, 2.0f)) == 1.0f)
3286 return -__builtin_inff();
3287 else
3288 return __builtin_inff();
3289 }
3290 }
3291 else if(isinff(x) && !__CPROVER_signf(x))
3292 {
3293 if(__CPROVER_signf(y))
3294 return +0.0f;
3295 else
3296 return __builtin_inff();
3297 }
3298 else if(fpclassify(x) == FP_ZERO && __CPROVER_signf(y))
3299 {
3300 errno = ERANGE;
3301#pragma CPROVER check push
3302#pragma CPROVER check disable "float-overflow"
3303 if(
3304 __CPROVER_signf(x) && nearbyintf(y) == y && fabsf(fmodf(y, 2.0f)) == 1.0f)
3305 {
3306 return -HUGE_VALF;
3307 }
3308 else
3309 return HUGE_VALF;
3310#pragma CPROVER check pop
3311 }
3312 else if(isnanf(x) || isnanf(y))
3313#pragma CPROVER check push
3314#pragma CPROVER check disable "float-div-by-zero"
3315 return 0.0f / 0.0f;
3316#pragma CPROVER check pop
3317
3318#ifndef _MSC_VER
3319 _Static_assert
3320#else
3321 static_assert
3322#endif
3323 (sizeof(float) == sizeof(int32_t),
3324 "bit width of float and int32_t should match");
3325 union
3326 {
3327 float f;
3328 int32_t i;
3329 } u = {x};
3330 int32_t bias = (1 << 23) * ((1 << 7) - 1);
3332 __CPROVER_assume(exp_c >= -722019 && exp_c <= 1);
3333#pragma CPROVER check push
3334#pragma CPROVER check disable "signed-overflow"
3335 float mult_result = y * (float)(u.i - (bias + exp_c));
3336#pragma CPROVER check pop
3337 if(fabsf(mult_result) > (float)(1 << 30))
3338 {
3339 errno = ERANGE;
3340#pragma CPROVER check push
3341#pragma CPROVER check disable "float-overflow"
3342 return y > 0.0f ? HUGE_VALF : 0.0f;
3343#pragma CPROVER check pop
3344 }
3345 u.i = (int32_t)mult_result + (bias + exp_c);
3346 return u.f;
3347}
3348
3349/* FUNCTION: powl */
3350
3351#ifndef __CPROVER_MATH_H_INCLUDED
3352# include <math.h>
3353# define __CPROVER_MATH_H_INCLUDED
3354#endif
3355
3356#ifndef __CPROVER_FLOAT_H_INCLUDED
3357# include <float.h>
3358# define __CPROVER_FLOAT_H_INCLUDED
3359#endif
3360
3361#ifndef __CPROVER_STDINT_H_INCLUDED
3362# include <stdint.h>
3363# define __CPROVER_STDINT_H_INCLUDED
3364#endif
3365
3366#ifndef __CPROVER_ERRNO_H_INCLUDED
3367# include <errno.h>
3368# define __CPROVER_ERRNO_H_INCLUDED
3369#endif
3370
3372
3373long double __builtin_infl(void);
3374
3375long double powl(long double x, long double y)
3376{
3377 // see man pow (https://linux.die.net/man/3/pow)
3378 if(
3380 nearbyintl(y) != y)
3381 {
3382 errno = EDOM;
3383#pragma CPROVER check push
3384#pragma CPROVER check disable "float-div-by-zero"
3385 return 0.0l / 0.0l;
3386#pragma CPROVER check pop
3387 }
3388 else if(x == 1.0l)
3389 return 1.0l;
3390 else if(fpclassify(y) == FP_ZERO)
3391 return 1.0l;
3392 else if(fpclassify(x) == FP_ZERO && !__CPROVER_signld(y))
3393 {
3394 if(nearbyintl(y) == y && fabsl(fmodl(y, 2.0l)) == 1.0l)
3395 return x;
3396 else
3397 return +0.0l;
3398 }
3399 else if(isinfl(y))
3400 {
3401 // x == 1.0l and y-is-zero caught above
3402 if(x == -1.0l)
3403 return 1.0l;
3404 else if(__CPROVER_signld(y))
3405 {
3406 if(fabsl(x) < 1.0l)
3407 return __builtin_infl();
3408 else
3409 return +0.0l;
3410 }
3411 else
3412 {
3413 if(fabsl(x) < 1.0l)
3414 return +0.0l;
3415 else
3416 return __builtin_infl();
3417 }
3418 }
3419 else if(isinfl(x) && __CPROVER_signld(x))
3420 {
3421 if(__CPROVER_signld(y))
3422 {
3423 if(nearbyintl(y) == y && fabsl(fmodl(y, 2.0l)) == 1.0l)
3424 return -0.0l;
3425 else
3426 return +0.0l;
3427 }
3428 else
3429 {
3430 if(nearbyintl(y) == y && fabsl(fmodl(y, 2.0l)) == 1.0l)
3431 return -__builtin_infl();
3432 else
3433 return __builtin_infl();
3434 }
3435 }
3436 else if(isinfl(x) && !__CPROVER_signld(x))
3437 {
3438 if(__CPROVER_signld(y))
3439 return +0.0f;
3440 else
3441 return __builtin_infl();
3442 }
3443 else if(fpclassify(x) == FP_ZERO && __CPROVER_signld(y))
3444 {
3445 errno = ERANGE;
3446#pragma CPROVER check push
3447#pragma CPROVER check disable "float-overflow"
3448 if(
3449 __CPROVER_signld(x) && nearbyintl(y) == y &&
3450 fabsl(fmodl(y, 2.0l)) == 1.0l)
3451 {
3452 return -HUGE_VALL;
3453 }
3454 else
3455 return HUGE_VALL;
3456#pragma CPROVER check pop
3457 }
3458 else if(isnanl(x) || isnanl(y))
3459#pragma CPROVER check push
3460#pragma CPROVER check disable "float-div-by-zero"
3461 return 0.0l / 0.0l;
3462#pragma CPROVER check pop
3463
3464#if LDBL_MAX_EXP == DBL_MAX_EXP
3465 return pow(x, y);
3466#else
3467# ifndef _MSC_VER
3468 _Static_assert
3469# else
3470 static_assert
3471# endif
3472 (sizeof(long double) % sizeof(int32_t) == 0,
3473 "bit width of long double is a multiple of bit width of int32_t");
3474 union U
3475 {
3476 long double l;
3477 int32_t i[sizeof(long double) / sizeof(int32_t)];
3478 } u = {x};
3479# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3480 int32_t exponent = u.i[sizeof(long double) / sizeof(int32_t) - 1];
3481# else
3482 int32_t exponent = u.i[0];
3483# endif
3484 int32_t bias = (1 << 16) * ((1 << 14) - 1);
3486 __CPROVER_assume(exp_c >= -5641 && exp_c <= 1);
3487# pragma CPROVER check push
3488# pragma CPROVER check disable "signed-overflow"
3489 long double mult_result = y * (long double)(exponent - (bias + exp_c));
3490# pragma CPROVER check pop
3491 if(fabsl(mult_result) > (long double)(1 << 30))
3492 {
3493 errno = ERANGE;
3494# pragma CPROVER check push
3495# pragma CPROVER check disable "float-overflow"
3496 return y > 0.0l ? HUGE_VALL : 0.0l;
3497# pragma CPROVER check pop
3498 }
3499 int32_t result = (int32_t)mult_result + (bias + exp_c);
3500 union U result_u = {.i = {0}};
3501# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3502 result_u.i[sizeof(long double) / sizeof(int32_t) - 1] = result;
3503# else
3504 result_u.i[0] = result;
3505# endif
3506 return result_u.l;
3507#endif
3508}
3509
3510/* FUNCTION: fma */
3511
3512#ifndef __CPROVER_MATH_H_INCLUDED
3513# include <math.h>
3514# define __CPROVER_MATH_H_INCLUDED
3515#endif
3516
3517#ifndef __CPROVER_FENV_H_INCLUDED
3518# include <fenv.h>
3519# define __CPROVER_FENV_H_INCLUDED
3520#endif
3521
3522double __builtin_inf(void);
3523
3524double fma(double x, double y, double z)
3525{
3526 // see man fma (https://linux.die.net/man/3/fma)
3527#pragma CPROVER check push
3528#pragma CPROVER check disable "float-div-by-zero"
3529 if(isnan(x) || isnan(y))
3530 return 0.0 / 0.0;
3531 else if(
3532 (isinf(x) || isinf(y)) &&
3533 (fpclassify(x) == FP_ZERO || fpclassify(y) == FP_ZERO))
3534 {
3536 return 0.0 / 0.0;
3537 }
3538 else if(isnan(z))
3539 return 0.0 / 0.0;
3540
3541#pragma CPROVER check disable "float-overflow"
3542 double x_times_y = x * y;
3543 if(
3544 isinf(x_times_y) && isinf(z) &&
3546 {
3548 return 0.0 / 0.0;
3549 }
3550#pragma CPROVER check pop
3551
3552 if(isinf(x_times_y))
3553 {
3556 }
3557 // TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3558
3559 return x_times_y + z;
3560}
3561
3562/* FUNCTION: fmaf */
3563
3564#ifndef __CPROVER_MATH_H_INCLUDED
3565# include <math.h>
3566# define __CPROVER_MATH_H_INCLUDED
3567#endif
3568
3569#ifndef __CPROVER_FENV_H_INCLUDED
3570# include <fenv.h>
3571# define __CPROVER_FENV_H_INCLUDED
3572#endif
3573
3574float __builtin_inff(void);
3575
3576float fmaf(float x, float y, float z)
3577{
3578 // see man fma (https://linux.die.net/man/3/fma)
3579#pragma CPROVER check push
3580#pragma CPROVER check disable "float-div-by-zero"
3581 if(isnanf(x) || isnanf(y))
3582 return 0.0f / 0.0f;
3583 else if(
3584 (isinff(x) || isinff(y)) &&
3585 (fpclassify(x) == FP_ZERO || fpclassify(y) == FP_ZERO))
3586 {
3588 return 0.0f / 0.0f;
3589 }
3590 else if(isnanf(z))
3591 return 0.0f / 0.0f;
3592
3593#pragma CPROVER check disable "float-overflow"
3594 float x_times_y = x * y;
3595 if(
3596 isinff(x_times_y) && isinff(z) &&
3598 {
3600 return 0.0f / 0.0f;
3601 }
3602#pragma CPROVER check pop
3603
3604 if(isinff(x_times_y))
3605 {
3608 }
3609 // TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3610
3611 return x_times_y + z;
3612}
3613
3614/* FUNCTION: fmal */
3615
3616#ifndef __CPROVER_MATH_H_INCLUDED
3617# include <math.h>
3618# define __CPROVER_MATH_H_INCLUDED
3619#endif
3620
3621#ifndef __CPROVER_FENV_H_INCLUDED
3622# include <fenv.h>
3623# define __CPROVER_FENV_H_INCLUDED
3624#endif
3625
3626#ifndef __CPROVER_FLOAT_H_INCLUDED
3627# include <float.h>
3628# define __CPROVER_FLOAT_H_INCLUDED
3629#endif
3630
3631long double __builtin_infl(void);
3632
3633long double fmal(long double x, long double y, long double z)
3634{
3635 // see man fma (https://linux.die.net/man/3/fma)
3636#pragma CPROVER check push
3637#pragma CPROVER check disable "float-div-by-zero"
3638 if(isnanl(x) || isnanl(y))
3639 return 0.0l / 0.0l;
3640 else if(
3641 (isinfl(x) || isinfl(y)) &&
3642 (fpclassify(x) == FP_ZERO || fpclassify(y) == FP_ZERO))
3643 {
3645 return 0.0l / 0.0l;
3646 }
3647 else if(isnanl(z))
3648 return 0.0l / 0.0l;
3649
3650#pragma CPROVER check disable "float-overflow"
3651 long double x_times_y = x * y;
3652 if(
3653 isinfl(x_times_y) && isinfl(z) &&
3655 {
3657 return 0.0l / 0.0l;
3658 }
3659#pragma CPROVER check pop
3660
3661#if LDBL_MAX_EXP == DBL_MAX_EXP
3662 return fma(x, y, z);
3663#else
3664 if(isinfl(x_times_y))
3665 {
3668 }
3669 // TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3670
3671 return x_times_y + z;
3672#endif
3673}
3674
3675/* FUNCTION: __builtin_powi */
3676
3677#ifndef __CPROVER_MATH_H_INCLUDED
3678# include <math.h>
3679# define __CPROVER_MATH_H_INCLUDED
3680#endif
3681
3682#ifndef __CPROVER_STDINT_H_INCLUDED
3683# include <stdint.h>
3684# define __CPROVER_STDINT_H_INCLUDED
3685#endif
3686
3687#ifndef __CPROVER_ERRNO_H_INCLUDED
3688# include <errno.h>
3689# define __CPROVER_ERRNO_H_INCLUDED
3690#endif
3691
3693
3694double __builtin_inf(void);
3695
3696double __builtin_powi(double x, int y)
3697{
3698 // see man pow (https://linux.die.net/man/3/pow), specialized for y being an
3699 // integer
3700 if(x == 1.0)
3701 return 1.0;
3702 else if(y == 0)
3703 return 1.0;
3704 else if(fpclassify(x) == FP_ZERO && y > 0)
3705 {
3706 if(y % 2 == 1)
3707 return x;
3708 else
3709 return +0.0;
3710 }
3711 else if(isinf(x) && __CPROVER_signd(x))
3712 {
3713 if(y < 0)
3714 {
3715 if(-y % 2 == 1)
3716 return -0.0;
3717 else
3718 return +0.0;
3719 }
3720 else
3721 {
3722 if(y % 2 == 1)
3723 return -__builtin_inf();
3724 else
3725 return __builtin_inf();
3726 }
3727 }
3728 else if(isinf(x) && !__CPROVER_signd(x))
3729 {
3730 if(y < 0)
3731 return +0.0;
3732 else
3733 return __builtin_inf();
3734 }
3735 else if(fpclassify(x) == FP_ZERO && y < 0)
3736 {
3737 errno = ERANGE;
3738#pragma CPROVER check push
3739#pragma CPROVER check disable "float-overflow"
3740 if(__CPROVER_signd(x) && -y % 2 == 1)
3741 return -HUGE_VAL;
3742 else
3743 return HUGE_VAL;
3744#pragma CPROVER check pop
3745 }
3746 else if(isnan(x))
3747#pragma CPROVER check push
3748#pragma CPROVER check disable "float-div-by-zero"
3749 return 0.0 / 0.0;
3750#pragma CPROVER check pop
3751
3752#ifndef _MSC_VER
3753 _Static_assert
3754#else
3755 static_assert
3756#endif
3757 (sizeof(double) == 2 * sizeof(int32_t),
3758 "bit width of double is 2x bit width of int32_t");
3759 // https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
3760 union
3761 {
3762 double d;
3763 int32_t i[2];
3764 } u = {x};
3765 int32_t bias = (1 << 20) * ((1 << 10) - 1);
3767 __CPROVER_assume(exp_c >= -90253 && exp_c <= 1);
3768#pragma CPROVER check push
3769#pragma CPROVER check disable "signed-overflow"
3770#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3771 double mult_result = (double)(y) * (double)(u.i[1] - (bias + exp_c));
3772#else
3773 double mult_result = (double)(y) * (double)(u.i[0] - (bias + exp_c));
3774#endif
3775#pragma CPROVER check pop
3776 if(fabs(mult_result) > (double)(1 << 30))
3777 {
3778 errno = ERANGE;
3779#pragma CPROVER check push
3780#pragma CPROVER check disable "float-overflow"
3781 return y > 0 ? HUGE_VAL : 0.0;
3782#pragma CPROVER check pop
3783 }
3784#if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3785 u.i[1] = (int32_t)mult_result + (bias + exp_c);
3786 u.i[0] = 0;
3787#else
3788 u.i[0] = (int32_t)mult_result + (bias + exp_c);
3789 u.i[1] = 0;
3790#endif
3791 return u.d;
3792}
3793
3794/* FUNCTION: __builtin_powif */
3795
3796#ifndef __CPROVER_MATH_H_INCLUDED
3797# include <math.h>
3798# define __CPROVER_MATH_H_INCLUDED
3799#endif
3800
3801#ifndef __CPROVER_STDINT_H_INCLUDED
3802# include <stdint.h>
3803# define __CPROVER_STDINT_H_INCLUDED
3804#endif
3805
3806#ifndef __CPROVER_ERRNO_H_INCLUDED
3807# include <errno.h>
3808# define __CPROVER_ERRNO_H_INCLUDED
3809#endif
3810
3812
3813float __builtin_inff(void);
3814
3815float __builtin_powif(float x, int y)
3816{
3817 // see man pow (https://linux.die.net/man/3/pow), specialized for y being an
3818 // integer
3819 if(x == 1.0f)
3820 return 1.0f;
3821 else if(y == 0)
3822 return 1.0f;
3823 else if(fpclassify(x) == FP_ZERO && y > 0)
3824 {
3825 if(y % 2 == 1)
3826 return x;
3827 else
3828 return +0.0f;
3829 }
3830 else if(isinff(x) && __CPROVER_signf(x))
3831 {
3832 if(y < 0)
3833 {
3834 if(-y % 2 == 1)
3835 return -0.0f;
3836 else
3837 return +0.0f;
3838 }
3839 else
3840 {
3841 if(y % 2 == 1)
3842 return -__builtin_inff();
3843 else
3844 return __builtin_inff();
3845 }
3846 }
3847 else if(isinff(x) && !__CPROVER_signf(x))
3848 {
3849 if(y < 0)
3850 return +0.0f;
3851 else
3852 return __builtin_inff();
3853 }
3854 else if(fpclassify(x) == FP_ZERO && y < 0)
3855 {
3856 errno = ERANGE;
3857#pragma CPROVER check push
3858#pragma CPROVER check disable "float-overflow"
3859 if(__CPROVER_signf(x) && -y % 2 == 1)
3860 {
3861 return -HUGE_VALF;
3862 }
3863 else
3864 return HUGE_VALF;
3865#pragma CPROVER check pop
3866 }
3867 else if(isnanf(x))
3868#pragma CPROVER check push
3869#pragma CPROVER check disable "float-div-by-zero"
3870 return 0.0f / 0.0f;
3871#pragma CPROVER check pop
3872
3873#ifndef _MSC_VER
3874 _Static_assert
3875#else
3876 static_assert
3877#endif
3878 (sizeof(float) == sizeof(int32_t),
3879 "bit width of float and int32_t should match");
3880 union
3881 {
3882 float f;
3883 int32_t i;
3884 } u = {x};
3885 int32_t bias = (1 << 23) * ((1 << 7) - 1);
3887 __CPROVER_assume(exp_c >= -722019 && exp_c <= 1);
3888#pragma CPROVER check push
3889#pragma CPROVER check disable "signed-overflow"
3890 float mult_result = (float)(y) * (float)(u.i - (bias + exp_c));
3891#pragma CPROVER check pop
3892 if(fabsf(mult_result) > (float)(1 << 30))
3893 {
3894 errno = ERANGE;
3895#pragma CPROVER check push
3896#pragma CPROVER check disable "float-overflow"
3897 return y > 0 ? HUGE_VALF : 0.0f;
3898#pragma CPROVER check pop
3899 }
3900 u.i = (int32_t)mult_result + (bias + exp_c);
3901 return u.f;
3902}
3903
3904/* FUNCTION: __builtin_powil */
3905
3906#ifndef __CPROVER_MATH_H_INCLUDED
3907# include <math.h>
3908# define __CPROVER_MATH_H_INCLUDED
3909#endif
3910
3911#ifndef __CPROVER_FLOAT_H_INCLUDED
3912# include <float.h>
3913# define __CPROVER_FLOAT_H_INCLUDED
3914#endif
3915
3916#ifndef __CPROVER_STDINT_H_INCLUDED
3917# include <stdint.h>
3918# define __CPROVER_STDINT_H_INCLUDED
3919#endif
3920
3921#ifndef __CPROVER_ERRNO_H_INCLUDED
3922# include <errno.h>
3923# define __CPROVER_ERRNO_H_INCLUDED
3924#endif
3925
3927
3928long double __builtin_infl(void);
3929double __builtin_powi(double, int);
3930
3931long double __builtin_powil(long double x, int y)
3932{
3933 // see man pow (https://linux.die.net/man/3/pow), specialized for y being an
3934 // integer
3935 if(x == 1.0l)
3936 return 1.0l;
3937 else if(y == 0)
3938 return 1.0l;
3939 else if(fpclassify(x) == FP_ZERO && y > 0)
3940 {
3941 if(y % 2 == 1)
3942 return x;
3943 else
3944 return +0.0l;
3945 }
3946 else if(isinf(x) && __CPROVER_signld(x))
3947 {
3948 if(y < 0)
3949 {
3950 if(-y % 2 == 1)
3951 return -0.0l;
3952 else
3953 return +0.0l;
3954 }
3955 else
3956 {
3957 if(y % 2 == 1)
3958 return -__builtin_infl();
3959 else
3960 return __builtin_infl();
3961 }
3962 }
3963 else if(isinf(x) && !__CPROVER_signld(x))
3964 {
3965 if(y < 0)
3966 return +0.0f;
3967 else
3968 return __builtin_infl();
3969 }
3970 else if(fpclassify(x) == FP_ZERO && y < 0)
3971 {
3972 errno = ERANGE;
3973#pragma CPROVER check push
3974#pragma CPROVER check disable "float-overflow"
3975 if(__CPROVER_signld(x) && -y % 2 == 1)
3976 {
3977 return -HUGE_VALL;
3978 }
3979 else
3980 return HUGE_VALL;
3981#pragma CPROVER check pop
3982 }
3983 else if(isnan(x))
3984#pragma CPROVER check push
3985#pragma CPROVER check disable "float-div-by-zero"
3986 return 0.0l / 0.0l;
3987#pragma CPROVER check pop
3988
3989#if LDBL_MAX_EXP == DBL_MAX_EXP
3990 return __builtin_powi(x, y);
3991#else
3992# ifndef _MSC_VER
3993 _Static_assert
3994# else
3995 static_assert
3996# endif
3997 (sizeof(long double) % sizeof(int32_t) == 0,
3998 "bit width of long double is a multiple of bit width of int32_t");
3999 union U
4000 {
4001 long double l;
4002 int32_t i[sizeof(long double) / sizeof(int32_t)];
4003 } u = {x};
4004# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
4005 int32_t exponent = u.i[sizeof(long double) / sizeof(int32_t) - 1];
4006# else
4007 int32_t exponent = u.i[0];
4008# endif
4009 int32_t bias = (1 << 16) * ((1 << 14) - 1);
4011 __CPROVER_assume(exp_c >= -5641 && exp_c <= 1);
4012# pragma CPROVER check push
4013# pragma CPROVER check disable "signed-overflow"
4014 long double mult_result =
4015 (long double)y * (long double)(exponent - (bias + exp_c));
4016# pragma CPROVER check pop
4017 if(fabsl(mult_result) > (long double)(1 << 30))
4018 {
4019 errno = ERANGE;
4020# pragma CPROVER check push
4021# pragma CPROVER check disable "float-overflow"
4022 return y > 0 ? HUGE_VALL : 0.0l;
4023# pragma CPROVER check pop
4024 }
4025 int32_t result = (int32_t)mult_result + (bias + exp_c);
4026 union U result_u = {.i = {0}};
4027# if !defined(__BYTE_ORDER__) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
4028 result_u.i[sizeof(long double) / sizeof(int32_t) - 1] = result;
4029# else
4030 result_u.i[0] = result;
4031# endif
4032 return result_u.l;
4033#endif
4034}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
ait()
Definition ai.h:565
long double __CPROVER_round_to_integralld(long double, int)
double __CPROVER_fabs(double x)
__CPROVER_bool __CPROVER_isnormalld(long double f)
float __CPROVER_fmodf(float, float)
__CPROVER_bool __CPROVER_isnormald(double f)
float __CPROVER_round_to_integralf(float, int)
__CPROVER_bool __CPROVER_signf(float f)
__CPROVER_bool __CPROVER_isfinitef(float f)
__CPROVER_bool __CPROVER_isnanf(float f)
float __CPROVER_fabsf(float x)
__CPROVER_bool __CPROVER_isinfld(long double f)
long double __CPROVER_fabsl(long double x)
__CPROVER_bool __CPROVER_isfinited(double f)
__CPROVER_bool __CPROVER_isinff(float f)
__CPROVER_bool __CPROVER_isinfd(double f)
__CPROVER_bool __CPROVER_isnanld(long double f)
__CPROVER_bool __CPROVER_isfiniteld(long double f)
long double __CPROVER_fmodl(long double, long double)
__CPROVER_bool __CPROVER_isnormalf(float f)
double __CPROVER_fmod(double, double)
int __CPROVER_fpclassify(int, int, int, int, int,...)
void __CPROVER_assume(__CPROVER_bool assumption)
__CPROVER_bool __CPROVER_signld(long double f)
__CPROVER_bool __CPROVER_isnand(double f)
double __CPROVER_round_to_integrald(double, int)
__CPROVER_bool __CPROVER_signd(double f)
int feraiseexcept(int excepts)
Definition fenv.c:46
int fegetround(void)
Definition fenv.c:7
long int lroundf(float x)
Definition math.c:1788
int __fpclassifyl(long double f)
Definition math.c:457
float __builtin_fabsf(float f)
Definition math.c:38
float floorf(float x)
Definition math.c:1340
float expf(float x)
Definition math.c:2296
long int lrintf(float x)
Definition math.c:1659
float fminf(float f, float g)
Definition math.c:1197
float __VERIFIER_nondet_float(void)
double ceil(double x)
Definition math.c:1265
double fmax(double f, double g)
Definition math.c:1144
long long int llrintl(long double x)
Definition math.c:1742
long double floorl(long double x)
Definition math.c:1358
long double __VERIFIER_nondet_long_double(void)
long double sqrtl(long double d)
Definition math.c:1056
double nan(const char *str)
Definition math.c:659
long double powl(long double x, long double y)
Definition math.c:3375
long double fminl(long double f, long double g)
Definition math.c:1207
long int lrint(double x)
Definition math.c:1639
long long int llrintf(float x)
Definition math.c:1721
float __builtin_powif(float x, int y)
Definition math.c:3815
float remainderf(float x, float y)
Definition math.c:2086
double log2(double x)
Definition math.c:2660
int __CPROVER_islessf(float f, float g)
Definition math.c:61
int isinfl(long double ld)
Definition math.c:147
long long int llround(double x)
Definition math.c:1826
int __isnan(double d)
Definition math.c:170
int __CPROVER_isgreaterd(double f, double g)
Definition math.c:49
float fmaxf(float f, float g)
Definition math.c:1154
float __sort_of_CPROVER_remainderf(int rounding_mode, float x, float y)
Definition math.c:1953
long double exp2l(long double x)
Definition math.c:2192
float sqrtf(float f)
Definition math.c:886
int __fpclassifyf(float f)
Definition math.c:443
float rintf(float x)
Definition math.c:1590
short _dclass(double d)
Definition math.c:378
int signbit(double d)
Definition math.c:345
long double nearbyintl(long double x)
Definition math.c:1543
double fabs(double d)
Definition math.c:3
int __builtin_isnan(double d)
Definition math.c:275
double __builtin_powi(double x, int y)
Definition math.c:3696
float fdimf(float f, float g)
Definition math.c:1235
double __sort_of_CPROVER_remainder(int rounding_mode, double x, double y)
Definition math.c:1938
double fmod(double x, double y)
Definition math.c:2003
int __CPROVER_isgreaterequalf(float f, float g)
Definition math.c:53
int __builtin_isinfl(long double ld)
Definition math.c:268
long int lround(double x)
Definition math.c:1770
double __builtin_huge_val(void)
Definition math.c:300
long double fmaxl(long double f, long double g)
Definition math.c:1164
double __builtin_nan(const char *str)
Definition math.c:619
double cos(double x)
Definition math.c:557
double nearbyint(double x)
Definition math.c:1504
long long int llrint(double x)
Definition math.c:1701
long double roundl(long double x)
Definition math.c:1476
double log10(double x)
Definition math.c:2869
long double cosl(long double x)
Definition math.c:578
int32_t __VERIFIER_nondet_int32_t(void)
int __isnormalf(float f)
Definition math.c:214
double floor(double x)
Definition math.c:1323
double __builtin_inf(void)
Definition math.c:232
int __CPROVER_isunorderedd(double f, double g)
Definition math.c:92
float log2f(float x)
Definition math.c:2727
float cosf(float x)
Definition math.c:599
double nextUp(double d)
Definition math.c:766
short _fdclass(float f)
Definition math.c:412
int _dsign(double d)
Definition math.c:322
int __CPROVER_islessgreaterd(double f, double g)
Definition math.c:81
int __isnanf(float f)
Definition math.c:177
double round(double x)
Definition math.c:1441
int __isinfl(long double ld)
Definition math.c:154
float logf(float x)
Definition math.c:2517
long long int llroundf(float x)
Definition math.c:1844
double trunc(double x)
Definition math.c:1382
long long int llroundl(long double x)
Definition math.c:1863
int __CPROVER_islessgreaterf(float f, float g)
Definition math.c:77
int __finitef(float f)
Definition math.c:109
int __isinff(float f)
Definition math.c:140
int __CPROVER_isgreaterequald(double f, double g)
Definition math.c:57
int __CPROVER_islessd(double f, double g)
Definition math.c:65
double exp2(double x)
Definition math.c:2168
int __CPROVER_isgreaterf(float f, float g)
Definition math.c:45
float sinf(float x)
Definition math.c:536
int isinff(float f)
Definition math.c:133
int __isinf(double d)
Definition math.c:126
float ceilf(float x)
Definition math.c:1282
long double truncl(long double x)
Definition math.c:1417
int __CPROVER_islessequald(double f, double g)
Definition math.c:73
int __CPROVER_rounding_mode
Definition math.c:1521
long double __sort_of_CPROVER_remainderl(int rounding_mode, long double x, long double y)
Definition math.c:1968
long double __builtin_fabsl(long double d)
Definition math.c:31
float __builtin_inff(void)
Definition math.c:221
float nextUpf(float f)
Definition math.c:714
long double log2l(long double x)
Definition math.c:2795
double pow(double x, double y)
Definition math.c:3082
float fmaf(float x, float y, float z)
Definition math.c:3576
int __CPROVER_islessequalf(float f, float g)
Definition math.c:69
float truncf(float x)
Definition math.c:1399
long double fmodl(long double x, long double y)
Definition math.c:2037
float __builtin_nanf(const char *str)
Definition math.c:632
int isnanl(long double ld)
Definition math.c:191
double sin(double x)
Definition math.c:494
int __builtin_isinff(float f)
Definition math.c:261
double fmin(double f, double g)
Definition math.c:1187
short _ldclass(long double ld)
Definition math.c:395
float nearbyintf(float x)
Definition math.c:1523
int isnan(double d)
Definition math.c:163
int __signbit(double ld)
Definition math.c:366
long double modfl(long double x, long double *iptr)
Definition math.c:1927
int _ldsign(long double ld)
Definition math.c:329
long double remainderl(long double x, long double y)
Definition math.c:2103
long double fabsl(long double d)
Definition math.c:10
int isinf(double d)
Definition math.c:119
double sqrt(double d)
Definition math.c:979
int __finitel(long double ld)
Definition math.c:113
int __signbitd(double d)
Definition math.c:352
int __fpclassifyd(double d)
Definition math.c:429
float powf(float x, float y)
Definition math.c:3230
long int lrintl(long double x)
Definition math.c:1680
double fma(double x, double y, double z)
Definition math.c:3524
double __VERIFIER_nondet_double(void)
int isnormal(double d)
Definition math.c:207
float fabsf(float f)
Definition math.c:17
float nanf(const char *str)
Definition math.c:671
float modff(float x, float *iptr)
Definition math.c:1908
double copysign(double x, double y)
Definition math.c:2125
double log(double x)
Definition math.c:2449
double __builtin_fabs(double d)
Definition math.c:24
int _fdsign(float f)
Definition math.c:336
int __isnanl(long double ld)
Definition math.c:198
long double nextUpl(long double d)
Definition math.c:817
float roundf(float x)
Definition math.c:1458
int isnanf(float f)
Definition math.c:184
double exp(double x)
Definition math.c:2219
long double ceill(long double x)
Definition math.c:1300
double rint(double x)
Definition math.c:1571
float log10f(float x)
Definition math.c:2939
int __fpclassify(double d)
Definition math.c:482
long double fdiml(long double f, long double g)
Definition math.c:1245
long double copysignl(long double x, long double y)
Definition math.c:2155
long double log10l(long double x)
Definition math.c:3009
int __builtin_isinf(double d)
Definition math.c:254
long double __builtin_powil(long double x, int y)
Definition math.c:3931
long double sinl(long double x)
Definition math.c:515
float __builtin_huge_valf(void)
Definition math.c:289
float exp2f(float x)
Definition math.c:2180
long double expl(long double x)
Definition math.c:2371
long double rintl(long double x)
Definition math.c:1609
float fmodf(float x, float y)
Definition math.c:2020
int __finite(double d)
Definition math.c:105
long double fmal(long double x, long double y, long double z)
Definition math.c:3633
int __CPROVER_isunorderedf(float f, float g)
Definition math.c:85
int isfinite(double d)
Definition math.c:101
long double __builtin_huge_vall(void)
Definition math.c:311
long double nanl(const char *str)
Definition math.c:683
long double logl(long double x)
Definition math.c:2586
double remainder(double x, double y)
Definition math.c:2069
float copysignf(float x, float y)
Definition math.c:2140
long double __builtin_infl(void)
Definition math.c:243
long int lroundl(long double x)
Definition math.c:1807
int __builtin_isnanf(float f)
Definition math.c:282
double modf(double x, double *iptr)
Definition math.c:1890
int __signbitf(float f)
Definition math.c:359
double fdim(double f, double g)
Definition math.c:1225
int abs(int i)
Definition stdlib.c:10
Definition math.c:757
double f
Definition math.c:758
__CPROVER_bitvector[CHAR_BIT *sizeof(double)] bv
Definition math.c:762
Definition math.c:705
float f
Definition math.c:706
__CPROVER_bitvector[CHAR_BIT *sizeof(float)] bv
Definition math.c:710
Definition math.c:808
__CPROVER_bitvector[CHAR_BIT *sizeof(long double)] bv
Definition math.c:813
long double f
Definition math.c:809