Re: int64 or double

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Excellent explanation!

To address the question of why one would use a Floating Point value...
It depends a great deal upon what you need. Take geometric operations for
example.
If you are using PI and other multiplications / divisions, etc. where you
really need floating point values, Doubles make sense. However, programmers
need to consider the accuracy and write their code in such a way that the
final result will be "accurate enough". This sometimes means doing some
interesting things, one of which is ensuring that you perform your
calculations by grouping variables of similiar magnitude to minimize
rounding errors.

Additionally, the implementation of a Double is currently significantly
faster than Decimal due to very complex implementation details. I suspect
that at some point in the future, a Decimal datatype will be implemented
natively in hardware. At that point, a version of Decimal might unseat
Double for many applications.

An interesting bit of trivia...
While most CAD applications use the Double datatype for storing coordinates,
some of the fastest and best ones out there actually use Integers for
storage units. Interim math is performed using Doubles when needed, but
underneath the hood they are natively stored as long Integers. While at
first this may seem contrary to good sense due to rounding errors, in
implementation it gives some significant advantages. First, when Doubles are
not required, Integer operations are much faster. But when it comes to
rounding errors and such, when you base your system on Integers you can
almost exactly know and/or control the accuracy tolerance.

Gerald

"Stephany Young" <noone@localhost> wrote in message
news:u7ka14jdGHA.4532@xxxxxxxxxxxxxxxxxxxxxxx
The important thing is, for each range, to look at the signs of the
exponents.

The sign of the exponent indicates the direction in which to move the
decimal point.

+ means move the decimal to the right

- means move the decimal point to the left

To simplfy it for demonstration purposes let's take a floating point type
that allows the ranges:

-1.79E+3 to -4.94E-3
and
4.94E-3 to 1.79E+3

-1.79E+3 equates to -1790
-4.94E-3 equates to -0.00494
4.94E-3 equates to 0.00494
1.79E+3 equates to 1790

Remembering that not every number can be represented exactly in floating
point, you can see that we have ranges of:

-1790 through -0.00494 negative values
and
0.00494 through 1790 negative values

1790 is the upper limit, -1790 is the lower limit and the closest
representations of 0 that we can achieve are 0.00494 and -0.00494.

Now, extrapolate that example up to the Double type and you can see that
the
ranges are:

-1.79769313486231570E+308 through -4.94065645841246544E-324 for
negative
values
and
4.94065645841246544E-324 through 1.79769313486231570E+308 for positive
values

This can be rewritten as:


-179769313486231570[...300 zeroes...]00000000
through
-0.000000[...310 zeroes...]000494065645841246544
for negative values
and
0.000000[...310 zeroes...]000494065645841246544
through
179769313486231570[...300 zeroes...]00000000
for positive values

This shows that 0 cannot be represented exactly as a Double and the
closest
representations of 0 that can be achieved are actually:

-0.000000[...310 zeroes...]000494065645841246544
and
0.000000[...310 zeroes...]000494065645841246544

Now, when it comes to dealing with the Decimal type, it holds a signed
128-bit (16-byte) value representing a 96-bit (12-byte) integer number
scaled by a variable power of 10.

The scaling factor specifies the number of digits to the right of the
decimal point and ranges from 0 through 28.

With a scale of 0 (no decimal places), the largest possible value is
+/-79,228,162,514,264,337,593,543,950,335
(+/-7.9228162514264337593543950335E+28).

With 28 decimal places, the largest value is
+/-7.9228162514264337593543950335, and the smallest nonzero value is
+/-0.0000000000000000000000000001 (+/-1E-28).

As you can see, for each decimal place that you have, you lose one
integral
place and vice-versa.

With no decimal places you can have the equivalent of a 29 digit number
with
a range of +79,228,162,514,264,337,593,543,950,335
to -79,228,162,514,264,337,593,543,950,335.

This is 10 digits wider than an Int64 (Long) and the maximum value is
approximately 8.5 bollions times larger.



"cj" <cj@xxxxxxxxxxxxx> wrote in message
news:uDf%23ZcjdGHA.3888@xxxxxxxxxxxxxxxxxxxxxxx
While I'm on the subject why would anyone use a floating point number
(double or single) if they're inaccurate? Why not use decimal? Other
than the decimal takes 16 bytes vs the doubles 8.

Also I'm still not sure why double and single list the values they
accept
in two ranges one for each side of 0. Do they not accept values around
0?
I'm sure they do but the documentation doesn't make sense to me.

ie: -1.79769313486231570E+308 through
-4.94065645841246544E-324 for negative values;
4.94065645841246544E-324
through 1.79769313486231570E+308 for positive values


cj wrote:
VB2003. I need a large positive integer. Which is larger int64 or
double?

I see int64 also apparently is known as long and will
hold -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.

But I'm not good with the E+??? notation so when I'm told double holds
-1.79769313486231570E+308 through
-4.94065645841246544E-324 for negative values; 4.94065645841246544E-324
through 1.79769313486231570E+308 for positive values.

What does that mean? is -1.79769313486231570E+308
= -1.79769313486231570
X whatever 1 with 308 zeros behind it is?

Plus double doesn't seem to hold 1, 2, 3, 4, 5 etc cause it gives two
ranges.

Sorry, I always felt math was for the computer to figure out not me.




.



Relevant Pages

  • Re: int64 or double
    ... To simplfy it for demonstration purposes let's take a floating point type that allows the ranges: ... -4.94E-3 equates to -0.00494 ... Remembering that not every number can be represented exactly in floating point, you can see that we have ranges of: ... The scaling factor specifies the number of digits to the right of the decimal point and ranges from 0 through 28. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to display a "double" in all its precision???
    ... between a mental model of floating point numbers as ranges, ... and also an exact mathematical value. ... For most purposes, this ...
    (comp.lang.java.programmer)
  • Re: C sucks at math? (help)
    ... I said I wouldn't try doubles in the real project, ... do similar calculations in a much bigger project and the problem I'm ... the floating point hardware or emulation does. ...
    (comp.lang.c)
  • Re: Floating point issue in sbcl 1.0.10?
    ... If you ensure that your floating point numbers are ... doubles, either by explicitly writing them that way, or by altering ... CL-USER> ... question leads off to all kinds of tangents. ...
    (comp.lang.lisp)
  • Re: C sucks at math? (help)
    ... I had just figured out that the emulation/casting was where it went ... It seems that doubles work for the toy-program, ... the floating point hardware or emulation does. ...
    (comp.lang.c)