[cig-commits] r4138 - in long/3D/Gale/trunk/src/StGermain: .
Base/Foundation/src Base/Foundation/tests
walter at geodynamics.org
walter at geodynamics.org
Tue Aug 1 01:53:13 PDT 2006
Author: walter
Date: 2006-08-01 01:53:12 -0700 (Tue, 01 Aug 2006)
New Revision: 4138
Modified:
long/3D/Gale/trunk/src/StGermain/
long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/CommonRoutines.c
long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.0of1.expected
long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.c
Log:
r2604 at earth: boo | 2006-08-01 01:50:34 -0700
r2583 at earth (orig r3706): PatrickSunter | 2006-07-24 19:19:37 -0700
Another fix to the floating point rounding routines:
* Added a special case so it can deal with numbers very close
to 0, since log10 goes to infinity there.
* Updated tests to verify this.
Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
- 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2603
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3705
+ 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2604
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3706
Modified: long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/CommonRoutines.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/CommonRoutines.c 2006-08-01 08:53:09 UTC (rev 4137)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/CommonRoutines.c 2006-08-01 08:53:12 UTC (rev 4138)
@@ -51,9 +51,15 @@
double StG_RoundDoubleToNSigFigs( double value, unsigned int nSigFigs ) {
double divisorPower;
double sign = 1.0;
+ double toleranceAroundZero = 1e-60;
assert( nSigFigs >= 1 );
+ /* Log goes to infinity at 0. Hence, we have to give up rounding if it gets too small */
+ if ( (value > (0.0 - toleranceAroundZero)) && (value < (0.0 + toleranceAroundZero)) ) {
+ return value;
+ }
+
/* Since logs can't deal with negatives, need to save the sign */
if ( value < 0 ) {
sign = -1.0;
Modified: long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.0of1.expected
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.0of1.expected 2006-08-01 08:53:09 UTC (rev 4137)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.0of1.expected 2006-08-01 08:53:12 UTC (rev 4138)
@@ -19,6 +19,14 @@
' ) = False
Testing rounding to certain number of decimal places:
+Value 0 rounded to 0 dec places was within tolerance of expected value 0.
+Value 0 rounded to 1 dec places was within tolerance of expected value 0.
+Value 0 rounded to 2 dec places was within tolerance of expected value 0.
+Value 0 rounded to 3 dec places was within tolerance of expected value 0.
+Value 3.4562e-30 rounded to 0 dec places was within tolerance of expected value 0.
+Value 3.4562e-30 rounded to 1 dec places was within tolerance of expected value 0.
+Value 3.4562e-30 rounded to 2 dec places was within tolerance of expected value 0.
+Value 3.4562e-30 rounded to 3 dec places was within tolerance of expected value 0.
Value 9.7324 rounded to 0 dec places was within tolerance of expected value 10.
Value 9.7324 rounded to 1 dec places was within tolerance of expected value 9.7.
Value 9.7324 rounded to 2 dec places was within tolerance of expected value 9.73.
@@ -41,6 +49,12 @@
Value 0.0043253 rounded to 3 dec places was within tolerance of expected value 0.004.
Testing rounding to certain number of significant figures:
+Value 0 rounded to 1 sig. figures was within tolerance of expected value 0.
+Value 0 rounded to 2 sig. figures was within tolerance of expected value 0.
+Value 0 rounded to 3 sig. figures was within tolerance of expected value 0.
+Value 3.4562e-30 rounded to 1 sig. figures was within tolerance of expected value 3e-30.
+Value 3.4562e-30 rounded to 2 sig. figures was within tolerance of expected value 3.5e-30.
+Value 3.4562e-30 rounded to 3 sig. figures was within tolerance of expected value 3.46e-30.
Value 9.7324 rounded to 1 sig. figures was within tolerance of expected value 10.
Value 9.7324 rounded to 2 sig. figures was within tolerance of expected value 9.7.
Value 9.7324 rounded to 3 sig. figures was within tolerance of expected value 9.73.
Modified: long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.c 2006-08-01 08:53:09 UTC (rev 4137)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.c 2006-08-01 08:53:12 UTC (rev 4138)
@@ -81,20 +81,34 @@
}
if ( rank == procToWatch ) {
- Index nTestValues = 5;
+ Index nTestValues = 7;
double testValues[] = {
+ 0.0,
+ 3.4562e-30,
9.7324,
97.654,
104.321,
-13762.1,
0.0043253 };
- double expectedRoundedToDecPlaces[5][4] = {
+ double tolerances[] = {
+ 1e-40,
+ 1e-40,
+ 1e-12,
+ 1e-12,
+ 1e-12,
+ 1e-12,
+ 1e-12 };
+ double expectedRoundedToDecPlaces[7][4] = {
+ { 0.0, 0.0, 0.0, 0.0 },
+ { 0.0, 0.0, 0.0, 0.0 },
{ 10., 9.7, 9.73, 9.732 },
{ 98., 97.7, 97.65, 97.654 },
{ 104., 104.3, 104.32, 104.321 },
{ -13762., -13762.1, -13762.10, -13762.100 },
{ 0., 0.0, 0.00, 0.004 } };
- double expectedRoundedToSigFigs[5][4] = {
+ double expectedRoundedToSigFigs[7][4] = {
+ { 0.0, 0.0, 0.0, 0.0 },
+ { 0.0, 3e-30, 3.5e-30, 3.46e-30 },
{ 0., 10, 9.7, 9.73 },
{ 0., 100, 98, 97.7 },
{ 0., 100, 100, 104 },
@@ -105,7 +119,6 @@
Index testValue_I;
Index nDecPlaces;
Index nSigFigs;
- double tolerance = 1e-12;
TestLMS( stream, "Acrobat", "BOAT", True );
TestLMS( stream, "Abracadabra", "Yabbadabbadoo", True );
@@ -133,7 +146,8 @@
testValues[testValue_I], nDecPlaces );
errorMargin = fabs( roundedValue -
expectedRoundedToDecPlaces[testValue_I][nDecPlaces] );
- if ( errorMargin <= tolerance ) {
+
+ if ( errorMargin <= tolerances[testValue_I] ) {
printf( "Value %8g rounded to %u dec places was within "
"tolerance of expected value %8g.\n",
testValues[testValue_I], nDecPlaces,
@@ -156,7 +170,7 @@
testValues[testValue_I], nSigFigs );
errorMargin = fabs( roundedValue -
expectedRoundedToSigFigs[testValue_I][nSigFigs] );
- if ( errorMargin <= tolerance ) {
+ if ( errorMargin <= tolerances[testValue_I] ) {
printf( "Value %8g rounded to %u sig. figures was within "
"tolerance of expected value %8g.\n",
testValues[testValue_I], nSigFigs,
More information about the cig-commits
mailing list