Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- From: cri@xxxxxxxx (Richard Harter)
- Date: Wed, 31 Oct 2007 15:47:45 GMT
On Wed, 31 Oct 2007 11:33:44 -0000, Lori
<steve.lorimer@xxxxxxxxx> wrote:
On Oct 30, 7:28 pm, Ed Prochak <edproc...@xxxxxxxxx> wrote:
IOW number of significant digits?
I guess
First, can you tell me how many significant digits exist in these
numbers
0.01e-21
0.00
0.000000
???????
1. 0.01e-21 = 0.00000000000000000000001: so 23 decimal places
2. 0.00 = 0: so 0 decimal places
3. 0.000000 = 0: so 0 decimal places
To use a New hampshire proverb:
you can't get there from here
What you need is to better define your requirements.
Ed
For sure. So the requirement is this: represent the decimal number as
an integer and a "format indicator", which is '0' - '9' for a positive
number with 0 to 9 decimal places respectively, or 'A' to 'J' for a
negative number with 0 to 9 decimal places respectively
Therefore: 34.125 would be 334125, and -10.0005 would be D100005
So my function is to take any "double" input, calculate the number of
dec places / precision / sig digits (not sure of correct terminology,
of if indeed there is any difference there), and return an integer.
ie: for
input 34.125 output 3
input -10.0005 output 4
input 0.0000 output 0
Your definition of precision does not correspond to standard
usage. In scientific work the precision of a number is the
number of places in decimal format using exponent notation with
no leading digits. Thus your examples are:
..34125e+2 -- precision = 5
-.100005e+2 -- precision = 6
..0000e+0 -- precision = 4
Briefly, the precision of a number (measurement or calculated
result) is the number of significant digits. In their internal
form floating point numbers all have approximately the same
precision (modulo binary to decimal conversion jitter).
Your "precision" is the number of places after the decimal point
when the number is converted from floating format (basically
exponential form with a fixed precision) to a fixed point format.
You might think about why you want to do this.
According to your description you wanted the "precision" of
floating point input. This doesn't make a whole lot of sense.
By your rules it is some constant minus the the exponent of
the input.
The impression I get from your description is that you want the
precision of a number specified by an input character string.
You might try to clarify what it is that you are after.
Richard Harter, cri@xxxxxxxx
http://home.tiac.net/~cri, http://www.varinoma.com
In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die
.
- References:
- Calculate the precision of a floating point number (ie: the number of decimal places)
- From: Lori
- Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- From: Ed Prochak
- Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- From: Lori
- Calculate the precision of a floating point number (ie: the number of decimal places)
- Prev by Date: Re: Does the order matter to add a sequence of floating numbers
- Next by Date: Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- Previous by thread: Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- Next by thread: Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- Index(es):
Relevant Pages
|