Repository navigation
Fix #15299: internalError with float conversion - #9105
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no problems. The PR fixes the internalError that occurs when a NaN or ±inf float value reaches Library::isFloatArgValid. Range specs already reject NaN and accept inf where the range allows it. Single values and !value specs no longer hand inf.0/nan.0 strings to MathLib::toDoubleNumber. The message now prints nan the same way on every libc, instead of nan on one and -nan on another. The new test covers NaN and +inf.
Testing
-
I built
cppcheckandtestrunnerin pr/ andcppcheckin base/. Both builds succeeded. -
./testrunner TestFunctions: 62 tests ran and 0 failed. -
I wrote scratch files that produce non-finite values through value flow and pass them to library functions with float valid ranges:
asin,acos,log,log10andsqrtwith +inf, -inf, NaN and -NaN.fmod(1.0, x), whose valid spec is!0.0, with inf, -inf and NaN.
For example:
void f1() { double c = 1e300; c = -c * c; c = asin(c); } void g1() { double c = 1e300; c = c*c; double r = fmod(1.0, c); (void)r; }
On these files base gives
error: Internal Error. MathLib::toDoubleNumber: conversion failed: -inf.0 [internalError](andinf.0for thefmodfile).The PR gives these results:
Invalid asin() argument nr 1. The value is -inf ..., and the same forsqrt(-inf)andlog10(-inf).The value is nan ...for NaN and -NaN arguments toasin,acos,logandsqrt.- No warning for
sqrt(inf),log(inf)orfmod(1.0, inf/nan), which is correct. - No internal errors.
Automated review of 48863a1 by Claude. The pull request was built and tested locally.
No description provided.