This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I have a question about the stdlib printf functions. If I use not "valid" floating point numbers, which is the case when memory is not initialized, then my snprintf function "hangs" (is looping internally). I have increased the heap to 500 and stack to 200. I am using CCS 5.1.1.00028 and MSP430. I tried compiler toos 4.0.0, 4.0.2, and 4.1.0 but nothing worked.
Do I have to provide some error callback functions? Where can I find detailed documentation about how to implement this functions?
Is this a bug?
If this is not a bug, how can I check if it is a valid floating point value?
Reproducible code:
void main(void) { char str[40]; volatile float test; ((char*)&test)[0] = 0x6d; ((char*)&test)[1] = 0x6d; ((char*)&test)[2] = 0; ((char*)&test)[3] = 0; while(1) { snprintf(str, 30, "%f", test); _NOP(); } }
Thanks,
Joachim
For IEEE-754 32-bit format, 0x00006d6d is 3.92546e-41f, which is a denormal (subnormal) number. The TI compiler doesn't support denormal numbers, and that in part manifests as library functions which can't handle them as input, and which do bad things like loop forever or return bogus results. You have to take care not to pass such numbers to any library function. There isn't a library function which tests whether a given bit pattern represents an IEEE-754 value that the library can handle.
In addition, it's technically undefined behavior to pass an uninitialized value to a library function, so doing so is not portable.
Hello Archaeologist,
ok - so does that mean if I want to create a robust software, I have to validate every floating point value that is loaded from external memory or internal flash? In my case I am storing floating point values in flash memory. Anyway, how do I check this correctly?
Suppose the memory from where the application is "loading" the float values gets corrupted (power loss or something else) and these values are not validated then the application crashes. There helps no watchdog or other mechanism because every thime the application crashes... Strange behavior in my opinion. Other implementations of printf I have seen prints a "NAN" or simply "0" but such behavior I havent seen until now.
Does TI somewhere inform customers about this behavior?
Thanks for helping,
Joachim
Unfortunately, there is no solution at the moment. The TI library doesn't make any sort of allowance for potentially corrupted floating-point input. The issue runs deeper than just printf; the underlying floating-point emulation functions need to be overhauled to support Inf, NaN, and denormals correctly. Certainly, we would prefer that printf at least not crash in the face of corrupted input, but fixing the floating-point emulation on a device that doesn't have floating-point hardware just doesn't get prioritized over the other work that needs to be done. I've submitted SDSCM00043971 to track this issue.
I can think of only one workaround: don't print float values that aren't known to be correct. Values can be assumed to be correct if they are generated by the program, or you could write a function to pick the bits apart and test for special values like NaN, Inf, -0, and denormal numbers. I know this is unpleasant, but that's the way it is today.
No, there is no documentation on the flaws of floating-point in TI compilers that I'm aware of.
Hello,
first thank you for your help. I am developing now embedded software for now about 12 years, worked with a lot of compilers until now. For me this is clearly a bug and maybe a big security risk for some applications, too. I will try to find an secure workaround.
> Certainly, we would prefer that printf at least not crash in the face of corrupted input, but fixing the floating-point emulation on a device that doesn't have floating-point hardware just doesn't get prioritized over the other work that needs to be done.
Hm - I thought that CCS is TI´s pfefered compiler for MSP430? No MSP430 device has an fpu as far as I know. Does TI really think that no one uses floating point operations in your devices without fpu? I hope not ;)
Sorry Archaeologist for this discussion - I just want to make clear that TI has to solve this issue and not only years later. Perhaps TI sees this with other eyes but I would not buy security devices if would know the controller has such "feature" ;)
TI should mention this somewhere that there exists this known problem.
Again thanks for helping,
Joachim
In the absence of documentation it is possible to run a floating-point test program. e.g. running Embedded System Paranoia: a tool for testing embedded system arithmetic on a MSP430F5438 when compiled for debug using MSP430 Compiler V4.1.0 produced the attached results. Note the overall rating for this test program of "Unacceptable".Archaeologist said:No, there is no documentation on the flaws of floating-point in TI compilers that I'm aware of.
COMMENT: ========================================= COMMENT: Welcome to ESP - Embedded System Paranoia COMMENT: Please let me know your experiences COMMENT: and suggestions at lesh@oakcomp.co.uk or COMMENT: L.Hatton@kent.ac.uk COMMENT: COMMENT: $Revision: 1.9 $ $Date: 2004/04/13 14:21:53 $ COMMENT: This version will attempt divide by zero. COMMENT: This version uses <stdio.h> COMMENT: This version uses double precision. nbits=64 COMMENT: ========================================= -------> Diagnosis resuming after Milestone 0, Page 1 COMMENT: -1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 PASSED : small integer tests are all OK. COMMENT: Searching for Radix and Precision. COMMENT: Radix = 2.00000000000000000e+00 COMMENT: Closest relative separation found is U1 = 1.11022302462515654e-16 COMMENT: Recalculating radix and precision COMMENT: confirms closest relative separation U1. COMMENT: Checking U1 for sanity... COMMENT: U1 is a sensible value COMMENT: Radix confirmed. -------> Diagnosis resuming after Milestone 10, Page 2 -------> Diagnosis resuming after Milestone 20, Page 3 COMMENT: The number of significant digits of the COMMENT: Radix is 5.29999999999999982e+01 -------> Diagnosis resuming after Milestone 25, Page 4 -------> Diagnosis resuming after Milestone 30, Page 5 COMMENT: Subtraction appears to be normalized, as it should be. COMMENT: Checking for guard digit in *, / and -. PASSED : *, /, and - appear to have guard digits, as they should. -------> Diagnosis resuming after Milestone 35, Page 6 COMMENT: Checking rounding on multiply, divide and add/subtract. FLAW : Multiplication neither chopped nor correctly rounded. -------> Diagnosis resuming after Milestone 40, Page 7 FLAW : Division neither chopped nor correctly rounded. -------> Diagnosis resuming after Milestone 45, Page 8 COMMENT: Addition/Subtraction neither rounds nor chops. COMMENT: Sticky bit used incorrectly or not at all. FLAW : Flaws are present due to lack of guard digits or round/chop failures -------> Diagnosis resuming after Milestone 50, Page 9 COMMENT: Testing multiplicative commutation COMMENT: with random pairs, trials = 20 PASSED : No failures found during these trials. -------> Diagnosis resuming after Milestone 60, Page 10 COMMENT: Running test of exp(log)). COMMENT: random X, (exp(log(x)) - x) trials = 20 -------> Diagnosis resuming after Milestone 64, Page 11 COMMENT: Running test of difference of two squares). COMMENT: integer X, (X**2-Y**2) - (X-Y)(X+Y) trials = 20 -------> Diagnosis resuming after Milestone 65, Page 12 COMMENT: Running transcendental test 1. COMMENT: random X, (sin(X)**2+cos(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 66, Page 13 COMMENT: Running transcendental test 2. COMMENT: random X, sin(4X) identity trials = 20 -------> Diagnosis resuming after Milestone 67, Page 14 COMMENT: Running hyperbolic test 1. COMMENT: random X, (cosh(X)**2-sinh(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 68, Page 15 COMMENT: Running test of square root(x). COMMENT: Testing integer X, sqrt(X * X) = X, trials = 20 COMMENT: Test for sqrt monotonicity. PASSED : sqrt has passed a test for Monotonicity. -------> Diagnosis resuming after Milestone 70, Page 16 -------> Diagnosis resuming after Milestone 80, Page 17 COMMENT: Testing whether sqrt is rounded or chopped. FLAW : Square root is neither chopped nor correctly rounded. COMMENT: Observed errors run from COMMENT: 0.00000000000000000e+00 to 5.00000000000000000e-01 ulps. -------> Diagnosis resuming after Milestone 85, Page 18 -------> Diagnosis resuming after Milestone 90, Page 19 COMMENT: Testing powers Z^i for small Integers Z and i. -------> Diagnosis resuming after Milestone 91, Page 20 PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 100, Page 21 COMMENT: Seeking Underflow thresholds UfThold and E0. -------> Diagnosis resuming after Milestone 110, Page 22 COMMENT: Smallest strictly positive number found COMMENT: is E0 = 2.22507385850721384e-308 COMMENT: Since comparison denies Z = 0, evaluating COMMENT: (Z + Z) / Z should be safe. COMMENT: (Z+Z)/Z is OK but this installation cannot COMMENT: signal any Over/Underflow. -------> Diagnosis resuming after Milestone 120, Page 23 FLAW : COMMENT: X != Z but X - Z = Zero COMMENT: X = 3.05947655544741171e-308, Z = 2.22507385850721384e-308 COMMENT: This is OK only if underflow signalled. COMMENT: X / Z = 1 + 3.75000000000000000e-01 COMMENT: The Underflow threshold is 2.22507385850721384e-308 COMMENT: Below this, a calculation may suffer larger Relative COMMENT: error than merely roundoff. -------> Diagnosis resuming after Milestone 121, Page 24 COMMENT: Since underflow occurs below the threshold COMMENT: UfThold = 2.00000000000000000e+00 ^ -1.02200000000000002e+03 COMMENT: only underflow could affect this expression. COMMENT: calculating yields: 0.00000000000000000e+00 PASSED : This computed value is O.K. -------> Diagnosis resuming after Milestone 130, Page 25 COMMENT: As X -> 1, Testing X^((X + 1) / (X - 1)) against exp(2). COMMENT: exp(2) = 7.38905609893065218e+00 PASSED : Accuracy seems adequate. -------> Diagnosis resuming after Milestone 140, Page 26 COMMENT: Testing powers Z^Q at four nearly extreme values. PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 150, Page 27 -------> Diagnosis resuming after Milestone 160, Page 28 COMMENT: Searching for Overflow threshold: COMMENT: This may generate an error. COMMENT: Can `Z = -Y' overflow? COMMENT: Trying it on Y = -inf PASSED : Seems O.K. COMMENT: Overflow threshold is V = 1.79769313486231646e+308 COMMENT: Overflow saturates at V0 = +inf COMMENT: No overflow should be signalled for V*1 = 1.79769313486231646e+308 COMMENT: No overflow should be signalled for V/1 = 1.79769313486231646e+308 COMMENT: Any overflow separating V*1 from COMMENT: V above is a DEFECT. -------> Diagnosis resuming after Milestone 161, Page 29 -------> Diagnosis resuming after Milestone 170, Page 30 DEFECT : COMMENT: Comparison alleges that what prints as Z =2.22507385850721384e-308 COMMENT: is too far from 2.22507385850721384e-308 DEFECT : COMMENT: Comparison alleges that what prints as Z =2.22507385850721384e-308 COMMENT: is too far from 2.22507385850721384e-308 -------> Diagnosis resuming after Milestone 175, Page 31 DEFECT : COMMENT: Comparison alleges that Z = 1.79769313486231646e+308 COMMENT: is too far from sqrt(Z) ^ 2 = +inf -------> Diagnosis resuming after Milestone 180, Page 32 -------> Diagnosis resuming after Milestone 190, Page 33 -------> Diagnosis resuming after Milestone 191, Page 34 SDEFECT: COMMENT: X / X differs from 1 when X =+inf COMMENT: X / X - 1/2 - 1/2 =nan -------> Diagnosis resuming after Milestone 200, Page 35 COMMENT: Trying to compute 1/0 gives +inf COMMENT: Trying to compute 0/0 gives nan -------> Diagnosis resuming after Milestone 210, Page 36 COMMENT: ========================================= COMMENT: Embedded System Paranoia SUMMARY COMMENT: DOUBLE PRECISION 64 bits COMMENT: Closest separation = 1.11022302462515654e-16 COMMENT: COMMENT: Number of FAILUREs encountered = 0 COMMENT: Number of SERIOUS DEFECTs discovered = 1 COMMENT: Number of DEFECTs discovered = 3 COMMENT: Number of FLAWs discovered = 5 COMMENT: FAILED : The arithmetic diagnosed has unacceptable COMMENT: Serious DEFECT. COMMENT: COMMENT: Rating ... COMMENT: COMMENT: Excellent COMMENT: Very good COMMENT: Good COMMENT: Acceptable COMMENT: =====> Unacceptable COMMENT: Broken COMMENT: COMMENT: ----------------------------------------- COMMENT: MATHS LIBRARY TESTS COMMENT: (should all give zero) COMMENT: COMMENT: Basic identities COMMENT: ln(1.0) = COMMENT: 0.00000000000000000e+00 COMMENT: exp(0.0) - 2.718281828459045235360287 = COMMENT: 0.00000000000000000e+00 COMMENT: Basic tests (Random over range 0<=X<=1) COMMENT: Test, exp(log(X)) - X = COMMENT: -2.22044604925031308e-16 -> 1.11022302462515654e-16 COMMENT: COMMENT: Transcendental identities COMMENT: Test, sin(1.0) - 0.84147098480789650665250 = COMMENT: -1.11022302462515654e-16 COMMENT: Test, cos(1.0) - 0.54030230586813971740094 = COMMENT: 0.00000000000000000e+00 COMMENT: Test, asin(1.0) - (pi/2) = COMMENT: 0.00000000000000000e+00 COMMENT: Test, acos(0.0) - (pi/2) = COMMENT: 0.00000000000000000e+00 COMMENT: Test, atan(1.0) - (pi/4) = COMMENT: 1.11022302462515654e-16 COMMENT: Transcendental tests (Random over range 0<=X<=1) COMMENT: Test, sin**2(X)+cos**2(X)-1.0 = COMMENT: -2.22044604925031308e-16 -> 2.22044604925031308e-16 COMMENT: Test, sin(4X)-(8.0*cos**4(X)*tan(X))+(4.0*cos(X)*sin(X)) = COMMENT: -8.88178419700125232e-16 -> 1.11022302462515654e-15 COMMENT: COMMENT: Hyperbolic identities COMMENT: Test, sinh(0.0) = COMMENT: 0.00000000000000000e+00 COMMENT: Test, cosh(0.0) - 1.0 = COMMENT: 0.00000000000000000e+00 COMMENT: Hyperbolic tests (Random over range 0<=X<=1) COMMENT: Test, cosh**2(X)-sinh**2(X)-1.0 = COMMENT: -3.33066907387546962e-16 -> 4.44089209850062616e-16 COMMENT: COMMENT: END OF TEST. COMMENT: =========================================
Results of single precision attached.
COMMENT: ========================================= COMMENT: Welcome to ESP - Embedded System Paranoia COMMENT: Please let me know your experiences COMMENT: and suggestions at lesh@oakcomp.co.uk or COMMENT: L.Hatton@kent.ac.uk COMMENT: COMMENT: $Revision: 1.9 $ $Date: 2004/04/13 14:21:53 $ COMMENT: This version will attempt divide by zero. COMMENT: This version uses <stdio.h> COMMENT: This version uses single precision, nbits=32 COMMENT: ========================================= -------> Diagnosis resuming after Milestone 0, Page 1 COMMENT: -1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 PASSED : small integer tests are all OK. COMMENT: Searching for Radix and Precision. COMMENT: Radix = 2.0000000e+00 COMMENT: Closest relative separation found is U1 = 5.9604645e-08 COMMENT: Recalculating radix and precision COMMENT: confirms closest relative separation U1. COMMENT: Checking U1 for sanity... COMMENT: U1 is a sensible value COMMENT: Radix confirmed. -------> Diagnosis resuming after Milestone 10, Page 2 -------> Diagnosis resuming after Milestone 20, Page 3 COMMENT: The number of significant digits of the COMMENT: Radix is 2.4000000e+01 -------> Diagnosis resuming after Milestone 25, Page 4 -------> Diagnosis resuming after Milestone 30, Page 5 COMMENT: Subtraction appears to be normalized, as it should be. COMMENT: Checking for guard digit in *, / and -. PASSED : *, /, and - appear to have guard digits, as they should. -------> Diagnosis resuming after Milestone 35, Page 6 COMMENT: Checking rounding on multiply, divide and add/subtract. FLAW : Multiplication neither chopped nor correctly rounded. -------> Diagnosis resuming after Milestone 40, Page 7 PASSED : Division appears to round correctly. -------> Diagnosis resuming after Milestone 45, Page 8 COMMENT: Addition/Subtraction neither rounds nor chops. COMMENT: Sticky bit used incorrectly or not at all. FLAW : Flaws are present due to lack of guard digits or round/chop failures -------> Diagnosis resuming after Milestone 50, Page 9 COMMENT: Testing multiplicative commutation COMMENT: with random pairs, trials = 20 PASSED : No failures found during these trials. -------> Diagnosis resuming after Milestone 60, Page 10 COMMENT: Running test of exp(log)). COMMENT: random X, (exp(log(x)) - x) trials = 20 -------> Diagnosis resuming after Milestone 64, Page 11 COMMENT: Running test of difference of two squares). COMMENT: integer X, (X**2-Y**2) - (X-Y)(X+Y) trials = 20 -------> Diagnosis resuming after Milestone 65, Page 12 COMMENT: Running transcendental test 1. COMMENT: random X, (sin(X)**2+cos(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 66, Page 13 COMMENT: Running transcendental test 2. COMMENT: random X, sin(4X) identity trials = 20 -------> Diagnosis resuming after Milestone 67, Page 14 COMMENT: Running hyperbolic test 1. COMMENT: random X, (cosh(X)**2-sinh(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 68, Page 15 COMMENT: Running test of square root(x). COMMENT: Testing integer X, sqrt(X * X) = X, trials = 20 COMMENT: Test for sqrt monotonicity. PASSED : sqrt has passed a test for Monotonicity. -------> Diagnosis resuming after Milestone 70, Page 16 -------> Diagnosis resuming after Milestone 80, Page 17 COMMENT: Testing whether sqrt is rounded or chopped. PASSED : Square root appears to be correctly rounded. -------> Diagnosis resuming after Milestone 85, Page 18 -------> Diagnosis resuming after Milestone 90, Page 19 COMMENT: Testing powers Z^i for small Integers Z and i. -------> Diagnosis resuming after Milestone 91, Page 20 PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 100, Page 21 COMMENT: Seeking Underflow thresholds UfThold and E0. -------> Diagnosis resuming after Milestone 110, Page 22 COMMENT: Smallest strictly positive number found COMMENT: is E0 = 1.1754944e-38 COMMENT: Since comparison denies Z = 0, evaluating COMMENT: (Z + Z) / Z should be safe. COMMENT: (Z+Z)/Z is OK but this installation cannot COMMENT: signal any Over/Underflow. -------> Diagnosis resuming after Milestone 120, Page 23 FLAW : COMMENT: X != Z but X - Z = Zero COMMENT: X = 1.6163047e-38, Z = 1.1754944e-38 COMMENT: This is OK only if underflow signalled. COMMENT: X / Z = 1 + 3.7500000e-01 COMMENT: The Underflow threshold is 1.1754944e-38 COMMENT: Below this, a calculation may suffer larger Relative COMMENT: error than merely roundoff. -------> Diagnosis resuming after Milestone 121, Page 24 COMMENT: Since underflow occurs below the threshold COMMENT: UfThold = 2.0000000e+00 ^ -1.2600000e+02 COMMENT: only underflow could affect this expression. COMMENT: calculating yields: 0.0000000e+00 PASSED : This computed value is O.K. -------> Diagnosis resuming after Milestone 130, Page 25 COMMENT: As X -> 1, Testing X^((X + 1) / (X - 1)) against exp(2). COMMENT: exp(2) = 7.3890557e+00 PASSED : Accuracy seems adequate. -------> Diagnosis resuming after Milestone 140, Page 26 COMMENT: Testing powers Z^Q at four nearly extreme values. PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 150, Page 27 -------> Diagnosis resuming after Milestone 160, Page 28 COMMENT: Searching for Overflow threshold: COMMENT: This may generate an error. COMMENT: Can `Z = -Y' overflow? COMMENT: Trying it on Y = -3.4028235e+38 PASSED : Seems O.K. COMMENT: Overflow threshold is V = 3.4028235e+38 COMMENT: Overflow saturates at V0 = 3.4028235e+38 COMMENT: No overflow should be signalled for V*1 = 3.4028235e+38 COMMENT: No overflow should be signalled for V/1 = 3.4028235e+38 COMMENT: Any overflow separating V*1 from COMMENT: V above is a DEFECT. -------> Diagnosis resuming after Milestone 161, Page 29 -------> Diagnosis resuming after Milestone 170, Page 30 -------> Diagnosis resuming after Milestone 175, Page 31 DEFECT : COMMENT: Comparison alleges that Z = 3.4028235e+38 COMMENT: is too far from sqrt(Z) ^ 2 = 3.4028233e+38 DEFECT : COMMENT: Comparison alleges that Z = 3.4028235e+38 COMMENT: is too far from sqrt(Z) ^ 2 = 3.4028233e+38 -------> Diagnosis resuming after Milestone 180, Page 32 -------> Diagnosis resuming after Milestone 190, Page 33 DEFECT : Badly COMMENT: unbalanced range: UfThold * V = 3.9999998e+00 is too far from 1. -------> Diagnosis resuming after Milestone 191, Page 34 SDEFECT: COMMENT: X / X differs from 1 when X =0.0000000e+00 COMMENT: X / X - 1/2 - 1/2 =nan -------> Diagnosis resuming after Milestone 200, Page 35 COMMENT: Trying to compute 1/0 gives nan COMMENT: Trying to compute 0/0 gives nan -------> Diagnosis resuming after Milestone 210, Page 36 COMMENT: ========================================= COMMENT: Embedded System Paranoia SUMMARY COMMENT: SINGLE PRECISION 32 bits COMMENT: Closest separation = 5.9604645e-08 COMMENT: COMMENT: Number of FAILUREs encountered = 0 COMMENT: Number of SERIOUS DEFECTs discovered = 1 COMMENT: Number of DEFECTs discovered = 3 COMMENT: Number of FLAWs discovered = 3 COMMENT: FAILED : The arithmetic diagnosed has unacceptable COMMENT: Serious DEFECT. COMMENT: COMMENT: Rating ... COMMENT: COMMENT: Excellent COMMENT: Very good COMMENT: Good COMMENT: Acceptable COMMENT: =====> Unacceptable COMMENT: Broken COMMENT: COMMENT: ----------------------------------------- COMMENT: MATHS LIBRARY TESTS COMMENT: (should all give zero) COMMENT: COMMENT: Basic identities COMMENT: ln(1.0) = COMMENT: 0.0000000e+00 COMMENT: exp(0.0) - 2.718281828459045235360287 = COMMENT: 0.0000000e+00 COMMENT: Basic tests (Random over range 0<=X<=1) COMMENT: Test, exp(log(X)) - X = COMMENT: -2.9802322e-08 -> 3.7252903e-09 COMMENT: COMMENT: Transcendental identities COMMENT: Test, sin(1.0) - 0.84147098480789650665250 = COMMENT: 0.0000000e+00 COMMENT: Test, cos(1.0) - 0.54030230586813971740094 = COMMENT: 0.0000000e+00 COMMENT: Test, asin(1.0) - (pi/2) = COMMENT: 0.0000000e+00 COMMENT: Test, acos(0.0) - (pi/2) = COMMENT: 0.0000000e+00 COMMENT: Test, atan(1.0) - (pi/4) = COMMENT: 0.0000000e+00 COMMENT: Transcendental tests (Random over range 0<=X<=1) COMMENT: Test, sin**2(X)+cos**2(X)-1.0 = COMMENT: 1.2384899e+17 -> 5.8818988e+32 COMMENT: Test, sin(4X)-(8.0*cos**4(X)*tan(X))+(4.0*cos(X)*sin(X)) = COMMENT: -4.7683722e-07 -> 4.7683716e-07 COMMENT: COMMENT: Hyperbolic identities COMMENT: Test, sinh(0.0) = COMMENT: 0.0000000e+00 COMMENT: Test, cosh(0.0) - 1.0 = COMMENT: 0.0000000e+00 COMMENT: Hyperbolic tests (Random over range 0<=X<=1) COMMENT: Test, cosh**2(X)-sinh**2(X)-1.0 = COMMENT: -1.7881393e-07 -> 1.1920929e-07 COMMENT: COMMENT: END OF TEST. COMMENT: =========================================
COMMENT: ========================================= COMMENT: Welcome to ESP - Embedded System Paranoia COMMENT: Please let me know your experiences COMMENT: and suggestions at lesh@oakcomp.co.uk or COMMENT: L.Hatton@kent.ac.uk COMMENT: COMMENT: $Revision: 1.9 $ $Date: 2004/04/13 14:21:53 $ COMMENT: This version will attempt divide by zero. COMMENT: This version uses <stdio.h> COMMENT: This version uses <setjmp.h> COMMENT: This version uses double precision. nbits=64 COMMENT: ========================================= -------> Diagnosis resuming after Milestone 0, Page 1 COMMENT: -1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 PASSED : small integer tests are all OK. COMMENT: Searching for Radix and Precision. COMMENT: Radix = 2.00000000000000000e+00 COMMENT: Closest relative separation found is U1 = 1.11022302462515654e-16 COMMENT: Recalculating radix and precision COMMENT: confirms closest relative separation U1. COMMENT: Checking U1 for sanity... COMMENT: U1 is a sensible value COMMENT: Radix confirmed. -------> Diagnosis resuming after Milestone 10, Page 2 -------> Diagnosis resuming after Milestone 20, Page 3 COMMENT: The number of significant digits of the COMMENT: Radix is 5.29999999999999982e+01 -------> Diagnosis resuming after Milestone 25, Page 4 -------> Diagnosis resuming after Milestone 30, Page 5 COMMENT: Subtraction appears to be normalized, as it should be. COMMENT: Checking for guard digit in *, / and -. PASSED : *, /, and - appear to have guard digits, as they should. -------> Diagnosis resuming after Milestone 35, Page 6 COMMENT: Checking rounding on multiply, divide and add/subtract. FLAW : Multiplication neither chopped nor correctly rounded. -------> Diagnosis resuming after Milestone 40, Page 7 FLAW : Division neither chopped nor correctly rounded. -------> Diagnosis resuming after Milestone 45, Page 8 COMMENT: Addition/Subtraction neither rounds nor chops. COMMENT: Sticky bit used incorrectly or not at all. FLAW : Flaws are present due to lack of guard digits or round/chop failures -------> Diagnosis resuming after Milestone 50, Page 9 COMMENT: Testing multiplicative commutation COMMENT: with random pairs, trials = 20 PASSED : No failures found during these trials. -------> Diagnosis resuming after Milestone 60, Page 10 COMMENT: Running test of exp(log)). COMMENT: random X, (exp(log(x)) - x) trials = 20 -------> Diagnosis resuming after Milestone 64, Page 11 COMMENT: Running test of difference of two squares). COMMENT: integer X, (X**2-Y**2) - (X-Y)(X+Y) trials = 20 -------> Diagnosis resuming after Milestone 65, Page 12 COMMENT: Running transcendental test 1. COMMENT: random X, (sin(X)**2+cos(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 66, Page 13 COMMENT: Running transcendental test 2. COMMENT: random X, sin(4X) identity trials = 20 -------> Diagnosis resuming after Milestone 67, Page 14 COMMENT: Running hyperbolic test 1. COMMENT: random X, (cosh(X)**2-sinh(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 68, Page 15 COMMENT: Running test of square root(x). COMMENT: Testing integer X, sqrt(X * X) = X, trials = 20 COMMENT: Test for sqrt monotonicity. PASSED : sqrt has passed a test for Monotonicity. -------> Diagnosis resuming after Milestone 70, Page 16 -------> Diagnosis resuming after Milestone 80, Page 17 COMMENT: Testing whether sqrt is rounded or chopped. FLAW : Square root is neither chopped nor correctly rounded. COMMENT: Observed errors run from COMMENT: 0.00000000000000000e+00 to 5.00000000000000000e-01 ulps. -------> Diagnosis resuming after Milestone 85, Page 18 -------> Diagnosis resuming after Milestone 90, Page 19 COMMENT: Testing powers Z^i for small Integers Z and i. -------> Diagnosis resuming after Milestone 91, Page 20 PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 100, Page 21 COMMENT: Seeking Underflow thresholds UfThold and E0. -------> Diagnosis resuming after Milestone 110, Page 22 COMMENT: Smallest strictly positive number found COMMENT: is E0 = 2.22507385850721384e-308 COMMENT: Since comparison denies Z = 0, evaluating COMMENT: (Z + Z) / Z should be safe. COMMENT: (Z+Z)/Z is OK provided Over/Underflow COMMENT: has NOT just been signaled. -------> Diagnosis resuming after Milestone 120, Page 23 FLAW : COMMENT: X != Z but X - Z = Zero COMMENT: X = 3.05947655544741171e-308, Z = 2.22507385850721384e-308 COMMENT: This is OK only if underflow signalled. COMMENT: X / Z = 1 + 3.75000000000000000e-01 COMMENT: The Underflow threshold is 2.22507385850721384e-308 COMMENT: Below this, a calculation may suffer larger Relative COMMENT: error than merely roundoff. -------> Diagnosis resuming after Milestone 121, Page 24 COMMENT: Since underflow occurs below the threshold COMMENT: UfThold = 2.00000000000000000e+00 ^ -1.02200000000000002e+03 COMMENT: only underflow could affect this expression. COMMENT: calculating yields: 0.00000000000000000e+00 PASSED : This computed value is O.K. -------> Diagnosis resuming after Milestone 130, Page 25 COMMENT: As X -> 1, Testing X^((X + 1) / (X - 1)) against exp(2). COMMENT: exp(2) = 7.38905609893065218e+00 PASSED : Accuracy seems adequate. -------> Diagnosis resuming after Milestone 140, Page 26 COMMENT: Testing powers Z^Q at four nearly extreme values. PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 150, Page 27 -------> Diagnosis resuming after Milestone 160, Page 28 COMMENT: Searching for Overflow threshold: COMMENT: This may generate an error. COMMENT: Can `Z = -Y' overflow? COMMENT: Trying it on Y = -inf PASSED : Seems O.K. COMMENT: Overflow threshold is V = 1.79769313486231646e+308 COMMENT: Overflow saturates at V0 = +inf COMMENT: No overflow should be signalled for V*1 = 1.79769313486231646e+308 COMMENT: No overflow should be signalled for V/1 = 1.79769313486231646e+308 COMMENT: Any overflow separating V*1 from COMMENT: V above is a DEFECT. -------> Diagnosis resuming after Milestone 161, Page 29 -------> Diagnosis resuming after Milestone 170, Page 30 -------> Diagnosis resuming after Milestone 175, Page 31 -------> Diagnosis resuming after Milestone 180, Page 32 -------> Diagnosis resuming after Milestone 190, Page 33 -------> Diagnosis resuming after Milestone 191, Page 34 -------> Diagnosis resuming after Milestone 200, Page 35 COMMENT: Trying to compute 1/0 gives +inf COMMENT: Trying to compute 0/0 gives nan -------> Diagnosis resuming after Milestone 210, Page 36 COMMENT: ========================================= COMMENT: Embedded System Paranoia SUMMARY COMMENT: DOUBLE PRECISION 64 bits COMMENT: Closest separation = 1.11022302462515654e-16 COMMENT: COMMENT: Number of FAILUREs encountered = 0 COMMENT: Number of SERIOUS DEFECTs discovered = 0 COMMENT: Number of DEFECTs discovered = 0 COMMENT: Number of FLAWs discovered = 5 COMMENT: PASSED : The arithmetic diagnosed seems satisfactory COMMENT: though flawed. COMMENT: COMMENT: Rating ... COMMENT: COMMENT: Excellent COMMENT: Very good COMMENT: =====> Good COMMENT: Acceptable COMMENT: Unacceptable COMMENT: Broken COMMENT: COMMENT: ----------------------------------------- COMMENT: MATHS LIBRARY TESTS COMMENT: (should all give zero) COMMENT: COMMENT: Basic identities COMMENT: ln(1.0) = COMMENT: 0.00000000000000000e+00 COMMENT: exp(0.0) - 2.718281828459045235360287 = COMMENT: 0.00000000000000000e+00 COMMENT: Basic tests (Random over range 0<=X<=1) COMMENT: Test, exp(log(X)) - X = COMMENT: -2.22044604925031308e-16 -> 1.11022302462515654e-16 COMMENT: COMMENT: Transcendental identities COMMENT: Test, sin(1.0) - 0.84147098480789650665250 = COMMENT: -1.11022302462515654e-16 COMMENT: Test, cos(1.0) - 0.54030230586813971740094 = COMMENT: 0.00000000000000000e+00 COMMENT: Test, asin(1.0) - (pi/2) = COMMENT: 0.00000000000000000e+00 COMMENT: Test, acos(0.0) - (pi/2) = COMMENT: 0.00000000000000000e+00 COMMENT: Test, atan(1.0) - (pi/4) = COMMENT: 1.11022302462515654e-16 COMMENT: Transcendental tests (Random over range 0<=X<=1) COMMENT: Test, sin**2(X)+cos**2(X)-1.0 = COMMENT: -2.22044604925031308e-16 -> 2.22044604925031308e-16 COMMENT: Test, sin(4X)-(8.0*cos**4(X)*tan(X))+(4.0*cos(X)*sin(X)) = COMMENT: -8.88178419700125232e-16 -> 1.11022302462515654e-15 COMMENT: COMMENT: Hyperbolic identities COMMENT: Test, sinh(0.0) = COMMENT: 0.00000000000000000e+00 COMMENT: Test, cosh(0.0) - 1.0 = COMMENT: 0.00000000000000000e+00 COMMENT: Hyperbolic tests (Random over range 0<=X<=1) COMMENT: Test, cosh**2(X)-sinh**2(X)-1.0 = COMMENT: -3.33066907387546962e-16 -> 4.44089209850062616e-16 COMMENT: COMMENT: END OF TEST. COMMENT: =========================================
COMMENT: ========================================= COMMENT: Welcome to ESP - Embedded System Paranoia COMMENT: Please let me know your experiences COMMENT: and suggestions at lesh@oakcomp.co.uk or COMMENT: L.Hatton@kent.ac.uk COMMENT: COMMENT: $Revision: 1.9 $ $Date: 2004/04/13 14:21:53 $ COMMENT: This version will attempt divide by zero. COMMENT: This version uses <stdio.h> COMMENT: This version uses <setjmp.h> COMMENT: This version uses single precision, nbits=32 COMMENT: ========================================= -------> Diagnosis resuming after Milestone 0, Page 1 COMMENT: -1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 PASSED : small integer tests are all OK. COMMENT: Searching for Radix and Precision. COMMENT: Radix = 2.0000000e+00 COMMENT: Closest relative separation found is U1 = 5.9604645e-08 COMMENT: Recalculating radix and precision COMMENT: confirms closest relative separation U1. COMMENT: Checking U1 for sanity... COMMENT: U1 is a sensible value COMMENT: Radix confirmed. -------> Diagnosis resuming after Milestone 10, Page 2 -------> Diagnosis resuming after Milestone 20, Page 3 COMMENT: The number of significant digits of the COMMENT: Radix is 2.4000000e+01 -------> Diagnosis resuming after Milestone 25, Page 4 -------> Diagnosis resuming after Milestone 30, Page 5 COMMENT: Subtraction appears to be normalized, as it should be. COMMENT: Checking for guard digit in *, / and -. PASSED : *, /, and - appear to have guard digits, as they should. -------> Diagnosis resuming after Milestone 35, Page 6 COMMENT: Checking rounding on multiply, divide and add/subtract. FLAW : Multiplication neither chopped nor correctly rounded. -------> Diagnosis resuming after Milestone 40, Page 7 PASSED : Division appears to round correctly. -------> Diagnosis resuming after Milestone 45, Page 8 COMMENT: Addition/Subtraction neither rounds nor chops. COMMENT: Sticky bit used incorrectly or not at all. FLAW : Flaws are present due to lack of guard digits or round/chop failures -------> Diagnosis resuming after Milestone 50, Page 9 COMMENT: Testing multiplicative commutation COMMENT: with random pairs, trials = 20 PASSED : No failures found during these trials. -------> Diagnosis resuming after Milestone 60, Page 10 COMMENT: Running test of exp(log)). COMMENT: random X, (exp(log(x)) - x) trials = 20 -------> Diagnosis resuming after Milestone 64, Page 11 COMMENT: Running test of difference of two squares). COMMENT: integer X, (X**2-Y**2) - (X-Y)(X+Y) trials = 20 -------> Diagnosis resuming after Milestone 65, Page 12 COMMENT: Running transcendental test 1. COMMENT: random X, (sin(X)**2+cos(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 66, Page 13 COMMENT: Running transcendental test 2. COMMENT: random X, sin(4X) identity trials = 20 -------> Diagnosis resuming after Milestone 67, Page 14 COMMENT: Running hyperbolic test 1. COMMENT: random X, (cosh(X)**2-sinh(X)**2) - 1.0 trials = 20 -------> Diagnosis resuming after Milestone 68, Page 15 COMMENT: Running test of square root(x). COMMENT: Testing integer X, sqrt(X * X) = X, trials = 20 COMMENT: Test for sqrt monotonicity. PASSED : sqrt has passed a test for Monotonicity. -------> Diagnosis resuming after Milestone 70, Page 16 -------> Diagnosis resuming after Milestone 80, Page 17 COMMENT: Testing whether sqrt is rounded or chopped. PASSED : Square root appears to be correctly rounded. -------> Diagnosis resuming after Milestone 85, Page 18 -------> Diagnosis resuming after Milestone 90, Page 19 COMMENT: Testing powers Z^i for small Integers Z and i. -------> Diagnosis resuming after Milestone 91, Page 20 PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 100, Page 21 COMMENT: Seeking Underflow thresholds UfThold and E0. -------> Diagnosis resuming after Milestone 110, Page 22 COMMENT: Smallest strictly positive number found COMMENT: is E0 = 1.1754944e-38 COMMENT: Since comparison denies Z = 0, evaluating COMMENT: (Z + Z) / Z should be safe. COMMENT: (Z+Z)/Z is OK provided Over/Underflow COMMENT: has NOT just been signaled. -------> Diagnosis resuming after Milestone 120, Page 23 FLAW : COMMENT: X != Z but X - Z = Zero COMMENT: X = 1.6163047e-38, Z = 1.1754944e-38 COMMENT: This is OK only if underflow signalled. COMMENT: X / Z = 1 + 3.7500000e-01 COMMENT: The Underflow threshold is 1.1754944e-38 COMMENT: Below this, a calculation may suffer larger Relative COMMENT: error than merely roundoff. -------> Diagnosis resuming after Milestone 121, Page 24 COMMENT: Since underflow occurs below the threshold COMMENT: UfThold = 2.0000000e+00 ^ -1.2600000e+02 COMMENT: only underflow could affect this expression. COMMENT: calculating yields: 0.0000000e+00 PASSED : This computed value is O.K. -------> Diagnosis resuming after Milestone 130, Page 25 COMMENT: As X -> 1, Testing X^((X + 1) / (X - 1)) against exp(2). COMMENT: exp(2) = 7.3890557e+00 PASSED : Accuracy seems adequate. -------> Diagnosis resuming after Milestone 140, Page 26 COMMENT: Testing powers Z^Q at four nearly extreme values. PASSED : ... no discrepancies found. -------> Diagnosis resuming after Milestone 150, Page 27 -------> Diagnosis resuming after Milestone 160, Page 28 COMMENT: Searching for Overflow threshold: COMMENT: This may generate an error. COMMENT: Can `Z = -Y' overflow? COMMENT: Trying it on Y = -3.4028235e+38 PASSED : Seems O.K. COMMENT: Overflow threshold is V = 3.4028235e+38 COMMENT: Overflow saturates at V0 = 3.4028235e+38 COMMENT: No overflow should be signalled for V*1 = 3.4028235e+38 COMMENT: No overflow should be signalled for V/1 = 3.4028235e+38 COMMENT: Any overflow separating V*1 from COMMENT: V above is a DEFECT. -------> Diagnosis resuming after Milestone 161, Page 29 -------> Diagnosis resuming after Milestone 170, Page 30 -------> Diagnosis resuming after Milestone 175, Page 31 -------> Diagnosis resuming after Milestone 180, Page 32 -------> Diagnosis resuming after Milestone 190, Page 33 -------> Diagnosis resuming after Milestone 191, Page 34 -------> Diagnosis resuming after Milestone 200, Page 35 COMMENT: Trying to compute 1/0 gives nan COMMENT: Trying to compute 0/0 gives nan -------> Diagnosis resuming after Milestone 210, Page 36 COMMENT: ========================================= COMMENT: Embedded System Paranoia SUMMARY COMMENT: SINGLE PRECISION 32 bits COMMENT: Closest separation = 5.9604645e-08 COMMENT: COMMENT: Number of FAILUREs encountered = 0 COMMENT: Number of SERIOUS DEFECTs discovered = 0 COMMENT: Number of DEFECTs discovered = 0 COMMENT: Number of FLAWs discovered = 3 COMMENT: PASSED : The arithmetic diagnosed seems satisfactory COMMENT: though flawed. COMMENT: COMMENT: Rating ... COMMENT: COMMENT: Excellent COMMENT: Very good COMMENT: =====> Good COMMENT: Acceptable COMMENT: Unacceptable COMMENT: Broken COMMENT: COMMENT: ----------------------------------------- COMMENT: MATHS LIBRARY TESTS COMMENT: (should all give zero) COMMENT: COMMENT: Basic identities COMMENT: ln(1.0) = COMMENT: 0.0000000e+00 COMMENT: exp(0.0) - 2.718281828459045235360287 = COMMENT: 0.0000000e+00 COMMENT: Basic tests (Random over range 0<=X<=1) COMMENT: Test, exp(log(X)) - X = COMMENT: -2.9802322e-08 -> 3.7252903e-09 COMMENT: COMMENT: Transcendental identities COMMENT: Test, sin(1.0) - 0.84147098480789650665250 = COMMENT: 0.0000000e+00 COMMENT: Test, cos(1.0) - 0.54030230586813971740094 = COMMENT: 0.0000000e+00 COMMENT: Test, asin(1.0) - (pi/2) = COMMENT: 0.0000000e+00 COMMENT: Test, acos(0.0) - (pi/2) = COMMENT: 0.0000000e+00 COMMENT: Test, atan(1.0) - (pi/4) = COMMENT: 0.0000000e+00 COMMENT: Transcendental tests (Random over range 0<=X<=1) COMMENT: Test, sin**2(X)+cos**2(X)-1.0 = COMMENT: -5.9604645e-08 -> 1.1920929e-07 COMMENT: Test, sin(4X)-(8.0*cos**4(X)*tan(X))+(4.0*cos(X)*sin(X)) = COMMENT: -4.7683716e-07 -> 4.7683716e-07 COMMENT: COMMENT: Hyperbolic identities COMMENT: Test, sinh(0.0) = COMMENT: 0.0000000e+00 COMMENT: Test, cosh(0.0) - 1.0 = COMMENT: 0.0000000e+00 COMMENT: Hyperbolic tests (Random over range 0<=X<=1) COMMENT: Test, cosh**2(X)-sinh**2(X)-1.0 = COMMENT: -1.7881393e-07 -> 1.1920929e-07 COMMENT: COMMENT: END OF TEST. COMMENT: =========================================
The test runs which reporting an overall rating of "Unacceptable" were compiled with the pre-defined symbol NOSETJMP.Chester Gillon said:Note the overall rating for this test program of "Unacceptable".
It turns out that there is a bug in esparanoia.c when NOSETJMP was defined which overwrote some variables. With NOSETJMP removed from the project, the overall rating for single and double precision was "Good". The updated results are attached.
I will contact the auther of Embedded System Paranoia.
Dear TI Support,
I know this post is a bit old, but I need to make a comment on this as it might potencially affect the firmware security in an applicaction with the DSP320F28335 (C28x).
This DSP has a FPU (floating point unit) so it has the floating point hardware, no need for software emulation. Also I have routines to inspect parameters in flash which could be viewed as integer, float, etc, being printed to a terminal.
For any reason, through a floating point operation, the parameter value gets NAN or Infinity (I believe the C28x treats both as Infinity). The sprint function makes the DSP to hang or it is in a loop (I could not check the actual state).
So here is a case that the NAN value is generated by code. Of course we should not pass a NAN to sprintf.
So I would much appreciate to know if is there a way to detect and prevent it from occurring, beyond if(x>FLOAT_MAX). If there existed any fucntion like isnan() or isinf() already supported by TI, I would like to hear about it.
Thanks.
Hi,
I have Compiler C2000 v6.1.3. The "math.h" in this version has no isnan() isinf() functions or macros. I have searched and surprisingly they are present in all the compilers except in C2000.
I also use function "atof" to make inverse conversion and I presume it has similar problem. I would like to make it bullet proof against any bad input from terminal. I have tried to input 1e305 and it just rebooted inmediately. It does not even set to NAN. I suspect "atof"could have a similar problem and I wonder if is there a fix or workaround, to avoid calling this function.
Thank you in advance
BR
Julio P��rez Arranz said:I have Compiler C2000 v6.1.3. The "math.h" in this version has no isnan() isinf() functions or macros.
The 6.2.x series of releases supports the isnan and isinf macros. The latest version available now is 6.2.7. Is it practical for you to upgrade your compiler?
Thanks and regards,
-George