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