Integers and ColdFusion

 
Jul 03, 2000
by Michael Dinowitz

I know this may sound like a silly question, but do you know what an integer is in ColdFusion? I expect your response will be "a non-decimal number," but have you thought about the size? Did you know that an integer in ColdFusion is defined as a 32-bit number? That is, a number between -2,147,483,648 and 2,147,483,647.

You may think that this is a really large number and no one would care about it, but you'd be wrong. There are a number of ColdFusion functions and operations that will only work on integers and throw an error message otherwise. This can be quite disconcerting when it happens, as the error message says you've got an integer problem and you're looking at the code and saying "it's right."

Luckily, there are not many things affected by this. The only mathematical operations that are affected are Mod (which returns the remainder of a division operation) and \ (which returns the whole number result of a division operation). One the other hand, there are a number of functions that are affected:

BitAnd() BitMaskClear() BitMaskRead()
BitMaskSet() BitNot() BitOr()
BitSHLN() BitSHRN() BitXor()
Randomize() RandRange() Chr()
DecrementValue() IncrementValue()
FormatBaseN() InputBaseN()
The only fix for this is to keep an eye on the numbers you're working with and use CFTRY/CFCATCH blocks to catch potential errors with the numbers you can't be sure of.
Privacy | FAQ | Site Map | About | Guidelines | Contact | Advertising | What is ColdFusion?
House of Fusion | ColdFusion Jobs | Blog of Fusion | AHP Hosting