Skip to content

Instantly share code, notes, and snippets.

@roryl
Last active October 27, 2016 13:58
Show Gist options
  • Save roryl/6edb0b617f29447556e515e4b7597281 to your computer and use it in GitHub Desktop.
Save roryl/6edb0b617f29447556e515e4b7597281 to your computer and use it in GitHub Desktop.
Lucee Numeric Type
<cfscript>
myNumber = 13.5837265748372615;
writeDump(myNumber);
</cfscript>
component {
public function init(){
}
function checkValue(){
}
public function onMissingMethod(){
}
}
<cfscript>
myNumber = 135837265748372615;
writeDump(myNumber);
</cfscript>
<cfscript>
myNumber = "135837265748372615";
writeDump(myNumber);
</cfscript>
<cfscript>
myNumber = javaCast("java.math.BigInteger", "135837265748372615");
writeDump(myNumber.toString());
</cfscript>
<cfscript>
BigInt = createObject("java", "java.math.BigInteger");
firstNumber = BigInt.init("135837265748372615");
secondNumber = BigInt.init("68584848283");
result = firstNumber.add(secondNumber);
writeDump(result.toString());
</cfscript>
<cfscript>
//Create the BigInteger object first
BigInt = createObject("java", "java.math.BigInteger");
//Create additional BigInteger objects by calling init()
firstNumber = BigInt.init("135837265748372615");
secondNumber = BigInt.init("584858686827");
writeDump(firstNumber.toString());
writeDump(secondNumber.toString());
</cfscript>
<cfscript>
BigInt = createObject("java", "java.math.BigInteger");
loops = 100000;
//Test 100,000 iterations of adding with BigInteger
firstNumber = BigInt.init("500");
secondNumber = BigInt.init("400");
timer type="outline" {
echo("Using java.math.BigInteger");
for(i=1; i <= loops; i++){
result = firstNumber.add(secondNumber);
}
}
//Test 100,000 iterations of adding with Lucee numeric
firstNumber = 500;
secondNumber = 400;
timer type="outline" {
echo("Using Lucee numeric");
for(i=1; i <= loops; i++){
result = firstNumber + secondNumber;
}
}
</cfscript>
<cfscript>
myNumber = 2001;
writeDump(myNumber);
</cfscript>
<cfscript>
myNumber = "2001";
added = myNumber + 500;
writeDump(added);
</cfscript>
<cfscript>
myNumber = "num2001";
added = myNumber + 500;
writeDump(added);
</cfscript>
<cfscript>
myNumber = 2001;
added = myNumber + 50;
multiplied = added * 1000;
writeDump(multiplied);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment