Created
December 2, 2016 12:40
-
-
Save delcypher/74a94de4786f27ce60d97a6460ead6af to your computer and use it in GitHub Desktop.
Approximately check if result of addition is subnormal with KLEE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "klee/klee.h" | |
#include <assert.h> | |
#include <math.h> | |
#include <stdio.h> | |
int is_subnormal(float f) { | |
return fpclassify(f) == FP_SUBNORMAL; | |
} | |
int main() { | |
float a = 0.0; | |
float b = 0.0; | |
klee_make_symbolic(&a, sizeof(a), "a"); | |
klee_make_symbolic(&b, sizeof(b), "b"); | |
float result = a + b; | |
if (!is_subnormal(result)) | |
return 0; | |
printf("Have subnormal result\n"); | |
// Approximately check the addition | |
// was exact. Not sure how good this | |
// approximation is. | |
assert( (result -b) == a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment