File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -38,16 +38,19 @@ uint64_t NumberCast<uint64_t>(const Napi::Number& num) {
38
38
return 0 ;
39
39
}
40
40
41
- if (value > static_cast <double >((1ULL << 53 ) - 1 )) {
41
+ static constexpr auto max_safe_integer = static_cast <double >((1ULL << 53 ) - 1 );
42
+ if (value > max_safe_integer) {
42
43
Warn (num.Env (),
43
44
" Value is larger than Number.MAX_SAFE_INTEGER and may have been rounded "
44
45
" inaccurately." );
45
46
}
46
47
47
48
/* If the next representable value of the double is beyond the maximum
48
49
integer, then assume the maximum integer. */
50
+ static constexpr auto max_uint64_as_double =
51
+ static_cast <double >(std::numeric_limits<uint64_t >::max ());
49
52
if (std::nextafter (value, std::numeric_limits<double >::infinity ())
50
- > std::numeric_limits< uint64_t >:: max () ) {
53
+ > max_uint64_as_double ) {
51
54
return std::numeric_limits<uint64_t >::max ();
52
55
}
53
56
You can’t perform that action at this time.
0 commit comments