Checks whether a number can be losslessly converted to a float.
| 990 | } |
| 991 | // Checks whether a number can be losslessly converted to a float. |
| 992 | bool IsLosslessFloat() const { |
| 993 | if (!IsNumber()) return false; |
| 994 | double a = GetDouble(); |
| 995 | if (a < static_cast<double>(-std::numeric_limits<float>::max()) |
| 996 | || a > static_cast<double>(std::numeric_limits<float>::max())) |
| 997 | return false; |
| 998 | double b = static_cast<double>(static_cast<float>(a)); |
| 999 | return a >= b && a <= b; // Prevent -Wfloat-equal |
| 1000 | } |
| 1001 | |
| 1002 | //@} |
| 1003 |