Re: Calculate the precision of a floating point number (ie: the number of decimal places)



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
.



Relevant Pages

  • Re: Floating point environment
    ... In all functions like fetestexcept, for instance, it is assumed that there is only one floating point environment ... one for double precision ... the 64 bit format and another for the 80 bit format. ... All versions of SSE use a status/control word separate from the main FPU, however, so they can indeed be considered a separate environment. ...
    (comp.std.c)
  • Re: Fastest way to compute floating point log and exp
    ... So far I've found that with a few tables and floating point MUL and ADD ... You didn't mention how much precision you need, nor for that matter what the log base is to be. ... bit easier than other bases because the floating point exponent is the integer portion of the log. ...
    (comp.arch.fpga)
  • Re: Floating point environment
    ... In all functions like fetestexcept, for instance, it is assumed that there is only one floating point environment ... one for double precision ... the 64 bit format and another for the 80 bit format. ... Those are different environments, but it has only tangentially to do with the format used. ...
    (comp.std.c)
  • Re: Range and precision of floating-point numbers
    ... values of operations with floating operands and values subject to the ... to a format whose range and precision may be greater than required by ... this is required by the standard. ...
    (comp.std.c)
  • Re: Quick Summary of WG5/J3 London meeting
    ... value returned is the one with the smallest decimal precision, ... It's that last phrase which implied to me some sort of ordering, ... select a decimal format if available, or perhaps insist on a binary ... 10**308), though due to exponent bias offsets, their exponent ranges ...
    (comp.lang.fortran)