Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #16312

Re: floating point

Date 2012-07-24 13:29 -0700
From Patricia Shanahan <pats@acm.org>
Newsgroups comp.lang.java.programmer
Subject Re: floating point
References <d94d1dd0-deb5-4259-b5a0-fb3d57e99c55@googlegroups.com>
Message-ID <g9Odnb6dKIkkmJLNnZ2dnUVZ_gudnZ2d@earthlink.com> (permalink)

Show all headers | View raw


On 7/24/2012 12:57 PM, bob smith wrote:
> I can never remember this.
>
> Let's say you have an integer and a float in an operation.  Is the result always a float?
>
> For instance;
>
> int x = 5;
>
> Is x/10.0f definitely a float?  Is this true for all ops?
>
>

It is true for all ops that do binary numeric promotion - see
http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2

Specifically, neither operand is a double and one operand is a float, so
the other is converted to float. The type of the result is the type of
the operands after that promotion, float.

May I ask why you are using float? Because of its very limited
precision, it is better to use double unless there is a specific reason
for preferring float and you are sure its precision is sufficient for
the calculation.

Patricia

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

floating point bob smith <bob@coolfone.comze.com> - 2012-07-24 12:57 -0700
  Re: floating point markspace <-@.> - 2012-07-24 13:01 -0700
    Re: floating point Lew <lewbloch@gmail.com> - 2012-07-24 13:21 -0700
      Re: floating point Gene Wirchenko <genew@ocis.net> - 2012-07-24 13:50 -0700
        Re: floating point Lew <noone@lewscanon.com> - 2012-07-25 06:33 -0700
          Re: floating point Gene Wirchenko <genew@ocis.net> - 2012-07-25 10:44 -0700
            Re: floating point Lew <lewbloch@gmail.com> - 2012-07-25 17:09 -0700
              Re: floating point Gene Wirchenko <genew@ocis.net> - 2012-07-25 17:42 -0700
                Re: floating point Jan Burse <janburse@fastmail.fm> - 2012-07-26 03:15 +0200
          Re: floating point Arne Vajhøj <arne@vajhoej.dk> - 2012-07-25 21:05 -0400
    Re: floating point Martin Gregorie <martin@address-in-sig.invalid> - 2012-07-24 20:34 +0000
  Re: floating point Patricia Shanahan <pats@acm.org> - 2012-07-24 13:29 -0700
    Re: floating point Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2012-07-25 12:22 +0300
      Re: floating point Arne Vajhøj <arne@vajhoej.dk> - 2012-07-25 10:54 -0400
      Re: floating point Roedy Green <see_website@mindprod.com.invalid> - 2012-07-25 13:29 -0700

csiph-web