Article View: borland.public.jbuilder.java.language
Article #17527Re: Floating-Point Range of Values...
From: John P. McGrath
Date: Wed, 28 Oct 1998 00:00
Date: Wed, 28 Oct 1998 00:00
35 lines
1572 bytes
1572 bytes
Rusli Usman <mrusli67@cbn.net.id> wrote:
> I understand java's Floating-Point data type consists of float (32-bits)
> and double (64-bits). If I want to find out the range of a type, for
> example, byte which has a maximum value of 127, all I have to do is as
> follows:
>
> byte bValue = 127;
>
> System.out.println("Min of Byte: "+ ++bValue);
>
> The output gives me:
>
> Min of Byte:-128
>
> So, how do I do that with floating-point? If I do ezactly like the byte
> data type, I don't see the min value. I know the min and max value of
> float, but how do I prove it in the code?
While I believe that any correct JVM must behave as you describe,
I have found that it is seldom (if ever) a good idea to employ
tricks like the one you describe.
Instead, you should use the MIN_VALUE and MAX_VALUE static
members that are defined in most of the wrapper classes that Java
defines (Byte, Character, Double, Float, Integer, Long, Short).
So to get the minimum value for a float, use Float.MIN_VALUE.
--
Regards,
John P. McGrath
<mcgrath@enter.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.10a0b8b419176319896eb@forums.inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<362DCA9D.CEFABA69@cbn.net.id>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,da07c345f9ebf065 X-Google-Attributes: gidf74b3,public From: mcgrath@enter.net (John P. McGrath) Subject: Re: Floating-Point Range of Values... Date: 1998/10/28 Message-ID: <MPG.10a0b8b419176319896eb@forums.inprise.com> X-Deja-AN: 405880158 References: <362DCA9D.CEFABA69@cbn.net.id> Organization: Software Consulting Services Newsgroups: borland.public.jbuilder.java.language