File: main.c

package info (click to toggle)
cbmc 5.12-5
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 92,512 kB
  • sloc: cpp: 301,761; ansic: 51,699; java: 27,534; python: 5,113; yacc: 4,756; makefile: 3,184; lex: 2,749; sh: 1,347; perl: 555; xml: 404; pascal: 203; ada: 36
file content (66 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
** subnormal-boundary.c
**
** Martin Brain
** martin.brain@cs.ox.ac.uk
** 25/07/12
**
** Regression tests for casting and classification around the subnormal boundary.
**
*/

#include <assert.h>
#include <math.h>

float nondet_float(void);

int main (void)
{
  #ifdef __GNUC__

  float smallestNormalFloat = 0x1.0p-126f;
  float largestSubnormalFloat = 0x1.fffffcp-127f;

  double v = 0x1.FFFFFFp-127;

  float f;


  // Check the encodings are correct
  assert(fpclassify(largestSubnormalFloat) == FP_SUBNORMAL);

  f = nondet_float();
  __CPROVER_assume(fpclassify(f) == FP_SUBNORMAL);
  assert(f <= largestSubnormalFloat);


  assert(fpclassify(smallestNormalFloat) == FP_NORMAL);

  f = nondet_float();
  __CPROVER_assume(fpclassify(f) == FP_NORMAL);
  assert(smallestNormalFloat <= fabs(f));

  assert(largestSubnormalFloat < smallestNormalFloat);


  // Check the ordering as doubles
  assert(((double)largestSubnormalFloat) < ((double)smallestNormalFloat));
  assert(((double)largestSubnormalFloat) < v);
  assert(v < ((double)smallestNormalFloat));


  // Check coercion to float
  assert((float)((double)largestSubnormalFloat) == largestSubnormalFloat);
  assert((float)((double)smallestNormalFloat) == smallestNormalFloat);

  assert(((double)smallestNormalFloat) - v <= v - ((double)largestSubnormalFloat));
  assert(((float)v) == smallestNormalFloat);

  f = nondet_float();
  __CPROVER_assume(fpclassify(f) == FP_SUBNORMAL);
  assert( ((float)((double)f)) == f );

  #endif

  return 0;
}