<< Chapter < Page | Chapter >> Page > |
What about other parameter values
Note that the method named toPrecision knows nothing about significant figures. It was up to me to figure out the desired number ofsignificant figures in advance and to pass that value as a parameter to themethod.
Although this has nothing to do with significant figures, it may be instructive to examine the behavior of the method named toPrecision for several different parameter values.
Figure 4 shows the result of replacing the parameter value of 5 in the call to the toPrecision method with the values in the first column of Figure 4 and displaying the value returned by the method.
Figure 4 . Behavior of the toPrecision method. |
---|
1 rounded = 2e+2
2 rounded = 2.3e+23 rounded = 232
4 rounded = 232.45 rounded = 232.40
6 rounded = 232.3997 rounded = 232.3990
10 rounded = 232.399005515 rounded = 232.399005526800
20 rounded = 232.39900552679998214 |
And the point is...
The point to this is to emphasize that the method named toPrecision is not a method that knows how to compute and display the required number of significant figures. Instead, according to theJavaScript documentation:
"The toPrecision() method formats a number to a specified length. A decimal point and nulls are added (if needed), to create the specified length."
It is up to you, the author of the script, to determine what that length should be and to provide that information as a parameter to the toPrecision method.
Combined operations
This is where things become a little hazy. I have been unable to find definitive information as to how to treat the precision and the number ofsignificant figures when doing computations that combine addition and/or subtraction with multiplication and/or division.
Two contradictory procedures
I have found two procedures documented on the web that seem to be somewhat contradictory. Both sources seem to say that you should perform the additionand/or subtraction first and that you should apply rule #1 to the results. However, they differ with regard to how stringently you apply that rulebefore moving on to the multiplication and/or division.
The more stringent procedure
One source seems to suggest that you should round the results of the addition and/or subtraction according to rule #1 and replace the addition or subtraction expression in your overall expressionwith the rounded result. Using that approach, you simply create one the factors that will be used later in the multiplication and/or division. That factor has awell-defined number of significant figures.
Then you proceed with the multiplication and/or division and adjust the number of significant figures in the final result according to rule #2 .
The less stringent procedure
The other source seems to suggest that you mentally round the results of the addition and/or subtraction according to rule #1 and make a note of the number of significant figures that would result if you wereto actually round the result. However, you should not actually round the result at that point in time. In other words, you should use the raw result of the addition and/or subtraction as a factor in theupcoming multiplication and/or division knowing that you may be carrying excess precision according to rule #1 .
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?