Re: 12.34f vs (float) 12.34
From: Stu Smith (stuarts_at_remove.digita.com)
Date: 02/12/04
- Next message: Dmitriy Lapshin [C# / .NET MVP]: "Re: C# and Macromedia Flash"
- Previous message: Einar Høst: "Reading text files using pointers?"
- In reply to: Jon Shemitz: "Re: 12.34f vs (float) 12.34"
- Next in thread: Jon Shemitz: "Re: 12.34f vs (float) 12.34"
- Reply: Jon Shemitz: "Re: 12.34f vs (float) 12.34"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 12 Feb 2004 11:54:14 -0000
"Jon Shemitz" <jon@midnightbeach.com> wrote in message
news:402A8C48.26F41DF7@midnightbeach.com...
> Stu Smith wrote:
>
> > HOW: it's called constant folding,
>
> Yes, thanks. Point of my question, though, is that I can imagine a few
> ways that this might be done:
>
> * Very straightforwardly, whereby "(float) 1.23" constructs a double
> value 1.23, then casts it to a single.
>
> * More convolutedly, whereby the constant folding operation sees the
> (float) cast being applied to an implicitly typed double, and goes
> back to the literal and reparses it as 1.23f.
>
> * Complex parsing, where cast followed by a literal parses the literal
> exactly as if it were 1.23f.
As far as I'm aware (and we're at the limits of my knowledge here), constant
folding is done at compile time, so option one is out of the question. I
believe the compiler makes passes over the statement/expression trees it has
generated, looking for certain patterns, and replacing them with
equivalents. I guess one pattern could be something like "(builtin value
type) constant -> new constant".
>
> The point being that in some cases the first approach might yield
> slightly different values than the first.
>
> > WHETHER: in theory I think they could in your example (but that's just
my
> > interpretation); section 11.1.3 of the CLI docs states:
>
> I'm not sure that ECMA-335 has much to say about the workings of the
> compiler ....
Don't know about that, but I do know that if you have a variable of type
float it's not guaranteed to be no more than a float.
>
> --
>
> programmer, author http://www.midnightbeach.com
> and father http://www.midnightbeach.com/hs
- Next message: Dmitriy Lapshin [C# / .NET MVP]: "Re: C# and Macromedia Flash"
- Previous message: Einar Høst: "Reading text files using pointers?"
- In reply to: Jon Shemitz: "Re: 12.34f vs (float) 12.34"
- Next in thread: Jon Shemitz: "Re: 12.34f vs (float) 12.34"
- Reply: Jon Shemitz: "Re: 12.34f vs (float) 12.34"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|