We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Is it the same float(number) as (float)number
Page Index Toggle Pages: 1
Is it the same float(number) as (float)number? (Read 538 times)
Is it the same float(number) as (float)number?
Sep 7th, 2009, 8:06am
 
Hi I gues Yes, but what are the implications of using one or the other?

Cheers
rS
Re: Is it the same float(number) as (float)number?
Reply #1 - Sep 7th, 2009, 9:54am
 
int i = 5;
float f = (float) i;

is probably faster than
float f = float(i);
(the former is made at compiler level, the latter is a function call).
But you can do float() on a wider range of types: strings, arrays, etc. It is more flexible. And takes care of error handling, etc.
Same for int().
Page Index Toggle Pages: 1