"operatable/comparable" max/min double values?

K

Kevin

Anyone has a idea of the max/min "operatable" double value?
By "operatable/comparable", I mean: we can add/minus a value from it
and get a different value.

The problem of Double.MAX_VALUE and Double.NEGATIVE_INFINITY are:
double d1 = Double.NEGATIVE_INFINITY;
double d2 = d1 + 100;
System.out.println(d1);
System.out.println(d2);
double d3 = Double.MAX_VALUE;
double d4 = d3 - 10000;
System.out.println(d3);
System.out.println(d4);
if (d3 > d4)
System.out.println("d3 is bigger.");

And the output will be:

-Infinity
-Infinity
1.7976931348623157E308
1.7976931348623157E308

See: minus 1000 from Double.Max_Value will NOT get a smaller value than
itself. So in this sensense, the Double.Max_Value is just a
none-operatable special "marker" value there.

I guess this has something to do with the floating representation
Double has.

For specific reasons: I need to define a "double" class which has some
special numbers, and behaviors as:

-MaxValue < specialNumberA < specialNumberB < "normal" range values <
specialNumberD < +MaxValue

But since the above code has shown that "Double.MAX_VALUE =
Double.MAX_VALUE -1000", I am not sure how to do it.

Any idea or where I am wrong at this?
Thanks.
 
S

Stefan Schulz

All doubles are, by necessity, rough estimates for actual numbers. They
all cover a (sometimes very large) range of ommitted values.

With that in mind, the question becomes rather mood. If you are in the
rough neighbourhood of 10^200, a measly 1000 more or less will not make
a difference.
 
E

Eric Sosman

Kevin wrote On 03/13/06 14:38,:
Anyone has a idea of the max/min "operatable" double value?
By "operatable/comparable", I mean: we can add/minus a value from it
and get a different value.

The problem of Double.MAX_VALUE and Double.NEGATIVE_INFINITY are:
double d1 = Double.NEGATIVE_INFINITY;
double d2 = d1 + 100;
System.out.println(d1);
System.out.println(d2);
double d3 = Double.MAX_VALUE;
double d4 = d3 - 10000;
System.out.println(d3);
System.out.println(d4);
if (d3 > d4)
System.out.println("d3 is bigger.");

And the output will be:

-Infinity
-Infinity
1.7976931348623157E308
1.7976931348623157E308

See: minus 1000 from Double.Max_Value will NOT get a smaller value than
itself. So in this sensense, the Double.Max_Value is just a
none-operatable special "marker" value there.

I guess this has something to do with the floating representation
Double has.

The representation has a finite number of digits, so
there is some "graininess." You can see the same effect
with ordinary decimal numbers and no computers at all:
subtract 5.4321 from 1.2345e100 using five properly-rounded
significant figures, and you'll see what's happening.
For specific reasons: I need to define a "double" class which has some
special numbers, and behaviors as:

-MaxValue < specialNumberA < specialNumberB < "normal" range values <
specialNumberD < +MaxValue

But since the above code has shown that "Double.MAX_VALUE =
Double.MAX_VALUE -1000", I am not sure how to do it.

You could start with Double.MAX_VALUE and subtract
larger and larger numbers until you observe a change:

double special;
for (double delta = 1.0; ; delta += delta) {
special = Double.MAX_VALUE - delta;
if (special < Double.MAX_VALUE)
break;
}

In decimal, this would be like successively subtracting
1, 10, 100, ... from 1.2345e100 (rounding all results to
five places) until you finally produce 1.2344e100; this
is the five-place number that's as large as possible but
distinctly less than 1.2345e100. Additional "special"
numbers can be found similarly.
 
K

Kevin

Thanks. Using your method, I found some of them:

1.7976931348623155E308
1.7976931348623153E308

And I have learned that java's double does not cover all the
consecutive integer numbers within its max_value and min_value range.
Hope I get it right.
 
I

IchBin

Kevin said:
Thanks. Using your method, I found some of them:

1.7976931348623155E308
1.7976931348623153E308

And I have learned that java's double does not cover all the
consecutive integer numbers within its max_value and min_value range.
Hope I get it right.

Try the BigDecimal Class

http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html




--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
P

Patricia Shanahan

Kevin said:
And I have learned that java's double does not cover all the
consecutive integer numbers within its max_value and min_value range.
Hope I get it right.

That is correct. I'll make a stronger statement. Almost all integers in
double's range are not represented.

Patricia
 
P

Patricia Shanahan

Kevin said:
Anyone has a idea of the max/min "operatable" double value?
By "operatable/comparable", I mean: we can add/minus a value from it
and get a different value.
....
See: minus 1000 from Double.Max_Value will NOT get a smaller value than
itself. So in this sensense, the Double.Max_Value is just a
none-operatable special "marker" value there.

Your test for "operatable" depends on the magic constant 1000. If you
subtract e.g. 1E300 from Double.MAX_VALUE you will get something
different.

The smallest double x such that x-y != x depends on the value of y.

Why 1000, rather than 1e300 or 42?

Patricia
 
J

John C. Bollinger

Kevin said:
And I have learned that java's double does not cover all the
consecutive integer numbers within its max_value and min_value range.

That's quite true, but double does cover all the integer numbers that
can be expressed as a Java int. In fact, the range of consecutive
integers that can be expressed by a double is about a million times
greater than the range of a a Java int.
 
C

Chris Uppal

John said:
In fact, the range of consecutive
integers that can be expressed by a double is about a million times
greater than the range of a a Java int.

Nitpick: I think it's more like 2 million times greater -- 2**53 values rather
than 2**32.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top