Re: 12.34f vs (float) 12.34

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Shemitz (jon_at_midnightbeach.com)
Date: 02/12/04


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


Relevant Pages

  • Re: Compiling
    ... >to compile, or are the symptoms different? ... >have process limits on memory (e.g., ... *** Error code 1 ... coredumpsize infinity kb ...
    (freebsd-questions)
  • Re: Perfrom Thru
    ... 'The statement will not compile without a change in syntax. ... Standard COBOL specifies no upper limit on such things ... It is recognized that these limits ...
    (comp.lang.cobol)
  • C Compiler Limit/Bug?
    ... I am trying to compile a large C program with large ... produces no error messages. ... What are the limits for C program size? ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: Integer types in format statements
    ... of, say, 1024 chars, then I would know that if I worked within that, my program would compile and ... compiler placing a limit on RECL of 128 chars. ... So there is nothing I can do, other than wait for bug reports, and then adjust my limits ... There are real physical printers with higher limits than that on line length, ...
    (comp.lang.fortran)