| 
	
 | 
 Posted by Chung Leong on 01/24/06 17:45 
Oli Filth wrote: 
 
> As a side-note: 
> I don't like the fact that even basic PHP code isn't portable between 
> platforms, i.e. it doesn't abstract away differences in platform bitwise 
> implementations of signed values. 
 
I don't really see why the operation would be platform dependent. If I 
remember correctly, a long is defined as 32 bit. Int is the one that 
varies between architectures. In PHP, a convert from double to integer 
is done by the DVAL_TO_LVAL macro, which is defined as: 
 
(l) = (d) > LONG_MAX ? (unsigned long) (d) : (long) (d) 
 
A cast to long should be the same even on a 64 bit OS/CPU. 
 
I wonder if it's a difference in the compiler or C library. Typically a 
cast from a float to a long is handled with a call to ftol(). Maybe the 
overflow behavior is different.
 
  
Navigation:
[Reply to this message] 
 |