[cig-commits] r4136 - 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:06 PDT 2006
Author: walter
Date: 2006-08-01 01:53:06 -0700 (Tue, 01 Aug 2006)
New Revision: 4136
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:
r2602 at earth: boo | 2006-08-01 01:50:31 -0700
r2581 at earth (orig r3704): PatrickSunter | 2006-07-23 23:50:58 -0700
One of my new functions to round to n significant figures
wasn't working for negative numbers since it used a log().
Fixed, and added a test to verify this.
Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
- 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2601
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3703
+ 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2602
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3704
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:01 UTC (rev 4135)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/CommonRoutines.c 2006-08-01 08:53:06 UTC (rev 4136)
@@ -50,9 +50,16 @@
double StG_RoundDoubleToNSigFigs( double value, unsigned int nSigFigs ) {
double divisorPower;
+ double sign = 1.0;
assert( nSigFigs >= 1 );
+ /* Since logs can't deal with negatives, need to save the sign */
+ if ( value < 0 ) {
+ sign = -1.0;
+ value = fabs(value);
+ }
+
/* Since interested in significant figures, need to work out the number of
zeros in the answer */
divisorPower = log10( value );
@@ -64,7 +71,7 @@
/* Similar approach to the decimal places rounder from here, except we use
the divisorPower we've just calculated */
- return floor( value / pow( 10., divisorPower ) + 0.5 ) * pow(10., divisorPower);
+ return sign * floor( value / pow( 10., divisorPower ) + 0.5 ) * pow(10., divisorPower);
}
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:01 UTC (rev 4135)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.0of1.expected 2006-08-01 08:53:06 UTC (rev 4136)
@@ -31,10 +31,10 @@
Value 104.321 rounded to 1 dec places was within tolerance of expected value 104.3.
Value 104.321 rounded to 2 dec places was within tolerance of expected value 104.32.
Value 104.321 rounded to 3 dec places was within tolerance of expected value 104.321.
-Value 13762.1 rounded to 0 dec places was within tolerance of expected value 13762.
-Value 13762.1 rounded to 1 dec places was within tolerance of expected value 13762.1.
-Value 13762.1 rounded to 2 dec places was within tolerance of expected value 13762.1.
-Value 13762.1 rounded to 3 dec places was within tolerance of expected value 13762.1.
+Value -13762.1 rounded to 0 dec places was within tolerance of expected value -13762.
+Value -13762.1 rounded to 1 dec places was within tolerance of expected value -13762.1.
+Value -13762.1 rounded to 2 dec places was within tolerance of expected value -13762.1.
+Value -13762.1 rounded to 3 dec places was within tolerance of expected value -13762.1.
Value 0.0043253 rounded to 0 dec places was within tolerance of expected value 0.
Value 0.0043253 rounded to 1 dec places was within tolerance of expected value 0.
Value 0.0043253 rounded to 2 dec places was within tolerance of expected value 0.
@@ -50,9 +50,9 @@
Value 104.321 rounded to 1 sig. figures was within tolerance of expected value 100.
Value 104.321 rounded to 2 sig. figures was within tolerance of expected value 100.
Value 104.321 rounded to 3 sig. figures was within tolerance of expected value 104.
-Value 13762.1 rounded to 1 sig. figures was within tolerance of expected value 10000.
-Value 13762.1 rounded to 2 sig. figures was within tolerance of expected value 14000.
-Value 13762.1 rounded to 3 sig. figures was within tolerance of expected value 13800.
+Value -13762.1 rounded to 1 sig. figures was within tolerance of expected value -10000.
+Value -13762.1 rounded to 2 sig. figures was within tolerance of expected value -14000.
+Value -13762.1 rounded to 3 sig. figures was within tolerance of expected value -13800.
Value 0.0043253 rounded to 1 sig. figures was within tolerance of expected value 0.004.
Value 0.0043253 rounded to 2 sig. figures was within tolerance of expected value 0.0043.
Value 0.0043253 rounded to 3 sig. figures was within tolerance of expected value 0.00433.
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:01 UTC (rev 4135)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/tests/testCommonRoutines.c 2006-08-01 08:53:06 UTC (rev 4136)
@@ -86,19 +86,19 @@
9.7324,
97.654,
104.321,
- 13762.1,
+ -13762.1,
0.0043253 };
double expectedRoundedToDecPlaces[5][4] = {
{ 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 },
+ { -13762., -13762.1, -13762.10, -13762.100 },
{ 0., 0.0, 0.00, 0.004 } };
double expectedRoundedToSigFigs[5][4] = {
{ 0., 10, 9.7, 9.73 },
{ 0., 100, 98, 97.7 },
{ 0., 100, 100, 104 },
- { 0., 10000, 14000, 13800 },
+ { 0., -10000, -14000, -13800 },
{ 0., 0.004, 0.0043, 0.00433 } };
double roundedValue;
double errorMargin;
More information about the cig-commits
mailing list