Re: Can I force precision loss?

From: Tony Morris (not_at_telling.you)
Date: 01/17/05


Date: Mon, 17 Jan 2005 08:27:19 GMT


"Mike Schilling" <mscottschilling@hotmail.com> wrote in message
news:rFCGd.11064$wZ2.2782@newssvr13.news.prodigy.com...
>
> "Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
> news:YcmdnVmpkZjPfXfcRVn-vw@texas.net...
> > "stevek" <someone@somewhere.org> wrote in message
> > news:7dyGd.14118$S11.1092@bgtnsc04-news.ops.worldnet.att.net...
> > [...]
> >> RandomCheck.java:21: possible loss of precision
> > [...]
> > It's called casting:
> >
> > long l = 500;
> > int i = (int) l;
>
>
> Casting long to int doesn't affect precsision, of course; either the
> conversion is exact or the result is completely different.
>
> double d;
> float f = (float)d;
>
> would reduce precision.
>
>

The compiler is issuing you with an error because your type conversion loses
information (64-bit type can't fit in a 32-bit type obviously).
By providing the explicit cast, you acknowledge the "loss of precision"
(theoretically speaking).

-- 
Tony Morris
http://xdweb.net/~dibblego/


Relevant Pages

  • Re: double to int conversion yields strange results
    ... giving me two different values for the int. ... the question raised is not about the precision of the ... is done in extended precision. ... It is the conversion to 'double' before the conversion to 'int' that ...
    (comp.lang.c)
  • Re: printf and style g
    ... a G conversion specifier), ... Let P equal the precision if nonzero, ... if a conversion with style E would have an exponent ... formatting and a precision of 2. ...
    (comp.std.c)
  • Re: double money
    ... precision in decimal due to this "wobbling precision". ... -- way faster conversion between external decimal and internal form ... -- exact representation of decimal fractions ... People seldom notice the loss of a bit or two of precision -- ...
    (comp.lang.c)
  • Re: printf and style g
    ... Let P equal the precision if nonzero, ... if a conversion with style E would have an exponent ... So I don't think an additional clarifying condition is necessary ...
    (comp.std.c)
  • Re: %a in printf
    ... where there is one hexadecimal digit (which is ... precision; if the precision is missing and FLT_RADIX ... used for a conversion and the letters ABCDEF for A ... If the value is zero, ...
    (comp.lang.c)