Saturday, 29 June 2013

CFML: Floating point bum-biting: Railo version (OpenBD just errored)

G'day
Just FYI (and because someone asked), these are the results of the code I used for last night's article on some floating point weirdness, when run on Railo. Code:


<cfoutput>
<cfif structKeyExists(server, "railo")>
    server.railo.version: #server.railo.version#<br>
<cfelse>
    server.coldFusion.productVersion: #server.coldFusion.productVersion#<br>
</cfif>
<hr>

<cfset theValue = 1.15>
<cfset theMultiplier = 100>
<cfset theDivisor = 5>
<cfset theProduct = theValue * theMultiplier>


Default<br>
#theProduct# % #theDivisor# = #theProduct % theDivisor#<br>
#theProduct# / #theDivisor# = #theProduct / theDivisor#<br>
#theProduct# \ #theDivisor# = #theProduct \ theDivisor#<br>
<hr>

Precision<br>
<cfset thePreciseProduct = precisionEvaluate(theValue * theMultiplier)>
#thePreciseProduct# % #theDivisor# = #thePreciseProduct % theDivisor#<br>
#thePreciseProduct# / #theDivisor# = #thePreciseProduct / theDivisor#<br>
#thePreciseProduct# \ #theDivisor# = #thePreciseProduct \ theDivisor#<br>
<hr>
</cfoutput>


Results:

server.railo.version: 4.1.0.011

Default
115 % 5 = 5
115 / 5 = 23
115 \ 5 = 22

Precision
115 % 5 = 5
115 / 5 = 23
115 \ 5 = 22


Reminder, ColdFusion gives this:

server.coldFusion.productVersion: 10,0,10,284825


Default
115 % 5 = 4
115 / 5 = 23
115 \ 5 = 22


Precision
115.00 % 5 = 0
115.00 / 5 = 23
115.00 \ 5 = 23

For the sake of completeness, I tried to run the code on OpenBD, but it turns out it doesn't have a precisionEvaluate() function, so it just errored. The "Default" statements all ran, and provided the same answer as ColdFusion did though.

So Railo gets the initial result wrong as well, but returns a different value to ColdFusion (which perhaps makes it doubly wrong, if we consider cross-compatibility), and Railo also gets two of the three expressions wrong using precisionEvaluate(), too. A rare win for ColdFusion, I think!

That's it. Hardly worth a whole article really. But too much for an adjunct to the existing one.

--
Adam