Skip to content

Commit

Permalink
add Dudeldu's fix for DBL_MIN/DBL_MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKrayer committed Jun 16, 2022
1 parent 2ae7993 commit 94ae214
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ struct
| Const (CReal (_, (FFloat | FDouble as fkind), Some str)) -> `Float (FD.of_string fkind str) (* prefer parsing from string due to higher precision *)
| Const (CReal (num, (FFloat | FDouble as fkind), None)) -> `Float (FD.of_const fkind num)
(* this is so far only for DBL_MIN/DBL_MAX as it is represented as LongDouble although it would fit into a double as well *)
| Const (CReal (_, (FLongDouble), Some str)) when str = "2.2250738585072014e-308L" -> `Float (FD.of_string FDouble str)
| Const (CReal (_, (FLongDouble), Some str)) when str = "1.7976931348623157e+308L" -> `Float (FD.of_string FDouble str)
| Const (CReal (num, (FLongDouble), _)) when Stdlib.Float.abs num = Stdlib.Float.min_float -> `Float (FD.of_const FDouble num)
| Const (CReal (num, (FLongDouble), _)) when Stdlib.Float.abs num = Stdlib.Float.max_float -> `Float (FD.of_const FDouble num)
(* String literals *)
| Const (CStr (x,_)) -> `Address (AD.from_string x) (* normal 8-bit strings, type: char* *)
| Const (CWStr (xs,_) as c) -> (* wide character strings, type: wchar_t* *)
Expand Down
5 changes: 2 additions & 3 deletions tests/regression/56-floats/06-library_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <float.h>

int main() {
double dbl_min = 2.2250738585072014e-308;
double inf = 1. / 0.;
double nan = 0. / 0.;

Expand All @@ -30,9 +29,9 @@ int main() {
assert(__builtin_isnan(nan)); //UNKNOWN

//__buitin_isnormal(x):
assert(__builtin_isnormal(dbl_min)); //SUCCESS!
assert(__builtin_isnormal(DBL_MIN)); //SUCCESS!
assert(__builtin_isnormal(0.0)); //FAIL!
assert(__builtin_isnormal(dbl_min / 2)); //FAIL!
assert(__builtin_isnormal(DBL_MIN / 2)); //FAIL!
assert(__builtin_isnormal(inf)); //UNKNOWN
assert(__builtin_isnormal(nan)); //UNKNOWN

Expand Down

0 comments on commit 94ae214

Please sign in to comment.