Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- From: Ed Prochak <edprochak@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 17:06:38 -0000
On Oct 31, 7:33 am, Lori <steve.lori...@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
I did not think you wanted the precision (since with internal floating
point you can't get it anyway)
You still have a problem. 10.0005 might be stored internally as
10.0004999 (not all real number values can be represented precisely in
binary floating point). so would you want the result to be 4 or 7 in
that case?
If you are going to count "decimal places", then I suggest you do
that. a simple approach would be to convert the internal binary
floating point to a string representing the decimal numbeer (IOW a
string as if you were going to print it out. Then count the digits in
that string.
I'm assuming this is home work, so I'll leave you to take that hint
and run with it.
Let us know how you do.
Ed
.
- 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: Calculate the precision of a floating point number (ie: the number of decimal places)
- Next by Date: Re: SortMerge avoids thrashing (was: Bailey's "two pass" FFT algorithm question)
- 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
|