I am develiping code for an aircraft and am testing some of our math routines. I am coming to find out that simple things like division by 0 oddly enough return 0 along with other strange issues.
My main question is that while sqrtf(-1.0) does return NAN, sqrt(-1.0) returns: 1.261340072242732e-157 which is not expected.
Here is the Variable dump:
test_number double 0x1F5BB55347BB24DC (Hex) 0xC30014F0
and here is the code
test_number = sqrt(-1.0); // NAN
How I got in this situation is that I am testing a wrapper for _Dclass and testing each return paramater. I was trying to force NAN into the test_number and couldn't. I couldn't even set it to the raw value of 0x7FF8000000000000. I finally poked memory with the value and got _DClass to return FP_NAN.
We are developing for the OMAP-L138
Code Composer Studio, Version: 5.1.0.09000
ARM compiler 4.9.4
Hello Mike,
there was another interesting discussion about floating point:
http://e2e.ti.com/support/development_tools/compiler/f/343/t/186149.aspx
Try to run the Embedded System Paranoia test tool mentioned in subsequent posts.
Christian
The TI compilers do not correctly handle NaN, Inf, negative zero, or denormal numbers in all cases. This is particularly noticeable when compiling for a device with no native floating-point instructions. There is presently no documentation of exactly where the compiler doesn't do what IEEE-754 requires.
Here is the output of Parinoia in SINGLE mode on the ARM. I will attache Double and DSP as I get them...
Hmmmmm - If you buy the test, it does not look good for small numbers.
[ARM9_0] COMMENT: =========================================
[ARM9_0] COMMENT: Welcome to ESP - Embedded System Paranoia
[ARM9_0] COMMENT: Please let me know your experiences
[ARM9_0] COMMENT: and suggestions at lesh@oakcomp.co.uk or
[ARM9_0] COMMENT: L.Hatton@kent.ac.uk
[ARM9_0] COMMENT:
[ARM9_0] COMMENT: $Revision: 1.9 $ $Date: 2004/04/13 14:21:53 $
[ARM9_0] COMMENT: This version will attempt divide by zero.
[ARM9_0] COMMENT: This version uses <stdio.h>
[ARM9_0] COMMENT: This version uses <setjmp.h>
[ARM9_0] COMMENT: This version uses single precision, nbits=32
[ARM9_0] -------> Diagnosis resuming after Milestone 0, Page 1
[ARM9_0] COMMENT: -1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240
[ARM9_0] PASSED : small integer tests are all OK.
[ARM9_0] COMMENT: Searching for Radix and Precision.
[ARM9_0] COMMENT: Radix = 2.0000000e+00
[ARM9_0] COMMENT: Closest relative separation found is U1 = 5.9604645e-08
[ARM9_0] COMMENT: Recalculating radix and precision
[ARM9_0] COMMENT: confirms closest relative separation U1.
[ARM9_0] COMMENT: Checking U1 for sanity...
[ARM9_0] COMMENT: U1 is a sensible value
[ARM9_0] COMMENT: Radix confirmed.
[ARM9_0] -------> Diagnosis resuming after Milestone 10, Page 2
[ARM9_0] -------> Diagnosis resuming after Milestone 20, Page 3
[ARM9_0] COMMENT: The number of significant digits of the
[ARM9_0] COMMENT: Radix is 2.4000000e+01
[ARM9_0] -------> Diagnosis resuming after Milestone 25, Page 4
[ARM9_0] -------> Diagnosis resuming after Milestone 30, Page 5
[ARM9_0] COMMENT: Subtraction appears to be normalized, as it should be.
[ARM9_0] COMMENT: Checking for guard digit in *, / and -.
[ARM9_0] PASSED : *, /, and - appear to have guard digits, as they should.
[ARM9_0] -------> Diagnosis resuming after Milestone 35, Page 6
[ARM9_0] COMMENT: Checking rounding on multiply, divide and add/subtract.
[ARM9_0] PASSED : Multiplication appears to round correctly.
[ARM9_0] -------> Diagnosis resuming after Milestone 40, Page 7
[ARM9_0] PASSED : Division appears to round correctly.
[ARM9_0] -------> Diagnosis resuming after Milestone 45, Page 8
[ARM9_0] COMMENT: Addition/Subtraction neither rounds nor chops.
[ARM9_0] COMMENT: Sticky bit used incorrectly or not at all.
[ARM9_0] FLAW : Flaws are present due to lack of guard digits or round/chop failures
[ARM9_0] -------> Diagnosis resuming after Milestone 50, Page 9
[ARM9_0] COMMENT: Testing multiplicative commutation
[ARM9_0] COMMENT: with random pairs, trials = 20
[ARM9_0] PASSED : No failures found during these trials.
[ARM9_0] -------> Diagnosis resuming after Milestone 60, Page 10
[ARM9_0] COMMENT: Running test of exp(log)).
[ARM9_0] COMMENT: random X, (exp(log(x)) - x) trials = 20
[ARM9_0] -------> Diagnosis resuming after Milestone 64, Page 11
[ARM9_0] COMMENT: Running test of difference of two squares).
[ARM9_0] COMMENT: integer X, (X**2-Y**2) - (X-Y)(X+Y) trials = 20
[ARM9_0] -------> Diagnosis resuming after Milestone 65, Page 12
[ARM9_0] COMMENT: Running transcendental test 1.
[ARM9_0] COMMENT: random X, (sin(X)**2+cos(X)**2) - 1.0 trials = 20
[ARM9_0] -------> Diagnosis resuming after Milestone 66, Page 13
[ARM9_0] COMMENT: Running transcendental test 2.
[ARM9_0] COMMENT: random X, sin(4X) identity trials = 20
[ARM9_0] -------> Diagnosis resuming after Milestone 67, Page 14
[ARM9_0] COMMENT: Running hyperbolic test 1.
[ARM9_0] COMMENT: random X, (cosh(X)**2-sinh(X)**2) - 1.0 trials = 20
[ARM9_0] -------> Diagnosis resuming after Milestone 68, Page 15
[ARM9_0] COMMENT: Running test of square root(x).
[ARM9_0] COMMENT: Testing integer X, sqrt(X * X) = X, trials = 20
[ARM9_0] COMMENT: Test for sqrt monotonicity.
[ARM9_0] PASSED : sqrt has passed a test for Monotonicity.
[ARM9_0] -------> Diagnosis resuming after Milestone 70, Page 16
[ARM9_0] -------> Diagnosis resuming after Milestone 80, Page 17
[ARM9_0] COMMENT: Testing whether sqrt is rounded or chopped.
[ARM9_0] PASSED : Square root appears to be correctly rounded.
[ARM9_0] -------> Diagnosis resuming after Milestone 85, Page 18
[ARM9_0] -------> Diagnosis resuming after Milestone 90, Page 19
[ARM9_0] COMMENT: Testing powers Z^i for small Integers Z and i.
[ARM9_0] -------> Diagnosis resuming after Milestone 91, Page 20
[ARM9_0] PASSED : ... no discrepancies found.
[ARM9_0] -------> Diagnosis resuming after Milestone 100, Page 21
[ARM9_0] COMMENT: Seeking Underflow thresholds UfThold and E0.
[ARM9_0] -------> Diagnosis resuming after Milestone 110, Page 22
[ARM9_0] COMMENT: Smallest strictly positive number found
[ARM9_0] COMMENT: is E0 = 1.1754944e-38
[ARM9_0] COMMENT: Since comparison denies Z = 0, evaluating
[ARM9_0] COMMENT: (Z + Z) / Z should be safe.
[ARM9_0] COMMENT: (Z+Z)/Z is OK provided Over/Underflow
[ARM9_0] COMMENT: has NOT just been signaled.
[ARM9_0] -------> Diagnosis resuming after Milestone 120, Page 23
[ARM9_0] FLAW :
[ARM9_0] COMMENT: X != Z but X - Z = Zero
[ARM9_0] COMMENT: X = 1.6163047e-38, Z = 1.1754944e-38
[ARM9_0] COMMENT: This is OK only if underflow signalled.
[ARM9_0] COMMENT: X / Z = 1 + 3.7500000e-01
[ARM9_0] COMMENT: The Underflow threshold is 1.1754944e-38
[ARM9_0] COMMENT: Below this, a calculation may suffer larger Relative
[ARM9_0] COMMENT: error than merely roundoff.
[ARM9_0] -------> Diagnosis resuming after Milestone 121, Page 24
[ARM9_0] COMMENT: Since underflow occurs below the threshold
[ARM9_0] COMMENT: UfThold = 2.0000000e+00 ^ -1.2600000e+02
[ARM9_0] COMMENT: only underflow could affect this expression.
[ARM9_0] COMMENT: calculating yields: 1.4240473e-306
[ARM9_0] SDEFECT: this is not between 0 and underflow
[ARM9_0]
[ARM9_0] COMMENT: threshold = 1.1754944e-38
[ARM9_0] -------> Diagnosis resuming after Milestone 130, Page 25
[ARM9_0] COMMENT: As X -> 1, Testing X^((X + 1) / (X - 1)) against exp(2).
[ARM9_0] COMMENT: exp(2) = 7.3890557e+00
[ARM9_0] PASSED : Accuracy seems adequate.
[ARM9_0] -------> Diagnosis resuming after Milestone 140, Page 26
[ARM9_0] COMMENT: Testing powers Z^Q at four nearly extreme values.
[ARM9_0] -------> Diagnosis resuming after Milestone 150, Page 27
[ARM9_0] -------> Diagnosis resuming after Milestone 160, Page 28
[ARM9_0] COMMENT: Searching for Overflow threshold:
[ARM9_0] COMMENT: This may generate an error.
[ARM9_0] COMMENT: Can `Z = -Y' overflow?
[ARM9_0] COMMENT: Trying it on Y = 1.4240473e-306
[ARM9_0] PASSED : Seems O.K.
[ARM9_0] COMMENT: Overflow threshold is V = 3.4028235e+38
[ARM9_0] COMMENT: Overflow saturates at V0 = 1.4240473e-306
[ARM9_0] COMMENT: No overflow should be signalled for V*1 = 3.4028235e+38
[ARM9_0] COMMENT: No overflow should be signalled for V/1 = 3.4028235e+38
[ARM9_0] COMMENT: Any overflow separating V*1 from
[ARM9_0] COMMENT: V above is a DEFECT.
[ARM9_0] -------> Diagnosis resuming after Milestone 161, Page 29
[ARM9_0] -------> Diagnosis resuming after Milestone 170, Page 30
[ARM9_0] -------> Diagnosis resuming after Milestone 175, Page 31
[ARM9_0] -------> Diagnosis resuming after Milestone 180, Page 32
[ARM9_0] -------> Diagnosis resuming after Milestone 190, Page 33
[ARM9_0] -------> Diagnosis resuming after Milestone 191, Page 34
[ARM9_0] -------> Diagnosis resuming after Milestone 200, Page 35
[ARM9_0] COMMENT: Trying to compute 1/0 gives 0.0000000e+00
[ARM9_0] COMMENT: Trying to compute 0/0 gives 0.0000000e+00
[ARM9_0] -------> Diagnosis resuming after Milestone 210, Page 36
[ARM9_0] COMMENT: Embedded System Paranoia SUMMARY
[ARM9_0] COMMENT: SINGLE PRECISION 32 bits
[ARM9_0] COMMENT: Closest separation = 5.9604645e-08
[ARM9_0] COMMENT: Number of FAILUREs encountered = 0
[ARM9_0] COMMENT: Number of SERIOUS DEFECTs discovered = 1
[ARM9_0] COMMENT: Number of DEFECTs discovered = 0
[ARM9_0] COMMENT: Number of FLAWs discovered = 2
[ARM9_0] FAILED : The arithmetic diagnosed has unacceptable
[ARM9_0] COMMENT: Serious DEFECT.
[ARM9_0] COMMENT: Rating ...
[ARM9_0] COMMENT: Excellent
[ARM9_0] COMMENT: Very good
[ARM9_0] COMMENT: Good
[ARM9_0] COMMENT: Acceptable
[ARM9_0] COMMENT: =====> Unacceptable
[ARM9_0] COMMENT: Broken
[ARM9_0] COMMENT: -----------------------------------------
[ARM9_0] COMMENT: MATHS LIBRARY TESTS
[ARM9_0] COMMENT: (should all give zero)
[ARM9_0] COMMENT: Basic identities
[ARM9_0] COMMENT: ln(1.0) =
[ARM9_0] COMMENT: 0.0000000e+00
[ARM9_0] COMMENT: exp(0.0) - 2.718281828459045235360287 =
[ARM9_0] COMMENT: Basic tests (Random over range 0<=X<=1)
[ARM9_0] COMMENT: Test, exp(log(X)) - X =
[ARM9_0] COMMENT: -2.9802322e-08 -> 3.7252903e-09
[ARM9_0] COMMENT: Transcendental identities
[ARM9_0] COMMENT: Test, sin(1.0) - 0.84147098480789650665250 =
[ARM9_0] COMMENT: Test, cos(1.0) - 0.54030230586813971740094 =
[ARM9_0] COMMENT: Test, asin(1.0) - (pi/2) =
[ARM9_0] COMMENT: Test, acos(0.0) - (pi/2) =
[ARM9_0] COMMENT: Test, atan(1.0) - (pi/4) =
[ARM9_0] COMMENT: Transcendental tests (Random over range 0<=X<=1)
[ARM9_0] COMMENT: Test, sin**2(X)+cos**2(X)-1.0 =
[ARM9_0] COMMENT: -5.9604645e-08 -> 1.1920929e-07
[ARM9_0] COMMENT: Test, sin(4X)-(8.0*cos**4(X)*tan(X))+(4.0*cos(X)*sin(X)) =
[ARM9_0] COMMENT: -4.7683716e-07 -> 4.7683716e-07
[ARM9_0] COMMENT: Hyperbolic identities
[ARM9_0] COMMENT: Test, sinh(0.0) =
[ARM9_0] COMMENT: Test, cosh(0.0) - 1.0 =
[ARM9_0] COMMENT: Hyperbolic tests (Random over range 0<=X<=1)
[ARM9_0] COMMENT: Test, cosh**2(X)-sinh**2(X)-1.0 =
[ARM9_0] COMMENT: -1.1920929e-07 -> 1.1920929e-07
[ARM9_0] COMMENT: END OF TEST.
[ARM9_0] enter main()
enter taskFxn()
6758.Parinoia.txt
So here are the "Embedded System Paranoia" results and I have to say I am rather disapointed in Texas Instruments. I would never have guessed they would be this sloppy especially on a DSP.
OMAP-L138 ARM9/DSP C674x and for a base line X68x (Visual Studio 2010 Express)
ARM9/SINGLE - Unacceptable [Serious Defect=1, FLAWS =2]
ARM9/DOUBLE - Good [FLAWS=4]
DSP/SINGLE - Good [FLASWS=1]
DSP/DOUBLE - Acceptable [Defects=2,FLAWS=2]
(Visual Studio 2010 Express)
X68x/SINGLE - Excelent []
X68x/DOUBLE - Excelent[]
The "Embedded System Paranoia" results produced when running on TMS570LS20216, compiled using TMS470 Code Generation Tools v4.9.4, produced a summary of "Excelent" for both single and double:
1778.TMS570LS20216_double_release.txt
6170.TMS570LS20216_single_release.txt
Guess that since the TMS570LS series has been certified for use in IEC 61508 SIL3 safety systems means that more effort has been placed in floating-point conformance compared to other devices.
That device has native floating-point support, which is the only reason it fares better on that test. The compiler is exactly the same, and for operations which cannot be done natively, there will still be some gaps here and there, particularly with constants like Inf and NaN.