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