Re: 12.34f vs (float) 12.34
From: Jon Shemitz (jon_at_midnightbeach.com)
Date: 02/12/04
- Next message: C# Learner: "Re: [OT] .NET Rant"
- Previous message: ron: "Looking equivalent class to HttpContext in Win app"
- In reply to: Stu Smith: "Re: 12.34f vs (float) 12.34"
- Next in thread: Stu Smith: "Re: 12.34f vs (float) 12.34"
- Reply: Stu Smith: "Re: 12.34f vs (float) 12.34"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 12 Feb 2004 13:31:46 -0800
Stu Smith wrote:
> > * Very straightforwardly, whereby "(float) 1.23" constructs a double
> > value 1.23, then casts it to a single.
> 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.
We're pretty much at the limits of my knowledge, too. I've written a
simple compiler, so I have some knowledge of the issues involved, but
that's about it.
But I don't see why you say that option 1 can be ruled out? Seems to
me: Parser sees a stream of digits followed by a . and another stream
of digits which is NOT followed by one of {d, f, m}. Bingo: a double
constant for the parse tree. Optimizer later comes along and sees the
expression cast(float, double constant) and does a compile-time cast,
reducing it to a float constant.
* * *
I suppose I should just do the brute force thing: write a simple test
program to generate reams of float constants, and see if (say)
2.22222222222222f != (float) 2.22222222222222.
Course, I'll probably find more than I care to know about method size
limits ....
-- programmer, author http://www.midnightbeach.com and father http://www.midnightbeach.com/hs
- Next message: C# Learner: "Re: [OT] .NET Rant"
- Previous message: ron: "Looking equivalent class to HttpContext in Win app"
- In reply to: Stu Smith: "Re: 12.34f vs (float) 12.34"
- Next in thread: Stu Smith: "Re: 12.34f vs (float) 12.34"
- Reply: Stu Smith: "Re: 12.34f vs (float) 12.34"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|