Checks whether a number can be losslessly converted to a double.
| 963 | |
| 964 | // Checks whether a number can be losslessly converted to a double. |
| 965 | bool IsLosslessDouble() const { |
| 966 | if (!IsNumber()) return false; |
| 967 | if (IsUint64()) { |
| 968 | uint64_t u = GetUint64(); |
| 969 | volatile double d = static_cast<double>(u); |
| 970 | return (d >= 0.0) |
| 971 | && (d < static_cast<double>(std::numeric_limits<uint64_t>::max())) |
| 972 | && (u == static_cast<uint64_t>(d)); |
| 973 | } |
| 974 | if (IsInt64()) { |
| 975 | int64_t i = GetInt64(); |
| 976 | volatile double d = static_cast<double>(i); |
| 977 | return (d >= static_cast<double>(std::numeric_limits<int64_t>::min())) |
| 978 | && (d < static_cast<double>(std::numeric_limits<int64_t>::max())) |
| 979 | && (i == static_cast<int64_t>(d)); |
| 980 | } |
| 981 | return true; // double, int, uint are always lossless |
| 982 | } |
| 983 | |
| 984 | // Checks whether a number is a float (possible lossy). |
| 985 | bool IsFloat() const { |