FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Suggestions
   Software Suggestions
(Moderator: fry)
   float-expressions
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: float-expressions  (Read 252 times)
pitaru

WWW Email
float-expressions
« on: Nov 5th, 2003, 5:47pm »

I notice many programming bugs that are related to this matter:
 
println(451/100); will return a (floor) rounded integer - the number 4.
 
to get the number 4.51, we would have to do:
 
println(451/100.0);  
or
println(451.0/100);
 
This is especially confusing with something like:
 
println(451/width);
 
I'm wondering if it wouldn't be more intuitive to have the pre-processor convert the expression (or at least width/height) to a float.  
 
fry


WWW
Re: float-expressions
« Reply #1 on: Nov 5th, 2003, 8:07pm »

this is a bummer but it's pretty essential to programming, so it's something that has to be learned.  
 
a compromise might be to have variables called widthf and heightf or something like that, which are floating-point values for the width and height, since they're so commonly needed in that form (they're needed in int form just as often, so it's a tossup which is the default).  
 
with the newer preproc, the syntax for float(width) now works, which is a lot less annoying. it's possible you can also do float(451/100) and have that do a floating point calc, though i'm not sure offhand.
 
Pages: 1 

« Previous topic | Next topic »