Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-5189 ParseNumber should support preciseMath #2452

Draft
wants to merge 1 commit into
base: 6.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ else if (strRadix.startsWith("hex")) {
if (strNumber.indexOf('.') != -1 && radix != DEC) throw new ExpressionException("The radix con only be [dec] for floating point numbers");

if (radix == DEC) {
return Caster.toDoubleValue(strNumber);
return Caster.toNumber(strNumber); // this should return a bigInteger when preciseMath is enabled
}
return Integer.parseInt(strNumber, radix);
}
Expand Down
34 changes: 34 additions & 0 deletions test/functions/LSParseNumber.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {
function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function afterAll(){
application action="update" precisemath=variables.preciseMath;
};

function run( testResults, testBox ){
describe( "Test LSParseNumber", function(){

it( "Test with Large number", function(){
var n = "2.305.843.009,01";
var locale = "german (standard)";
application action="update" preciseMath=false;
expect( LSParseNumber( n, locale ) ).toBe( 2305843009 );
application action="update" preciseMath=true;
expect( LSparseNumber( n, locale ) ).toBe( 2305843009 ); // but it returns 2305843009.01 ?
});

it( "Test with Large number", function(){
var n = "2.305.843.009.213.693.951,01";
var locale = "german (standard)";
application action="update" preciseMath=false;
expect( LSParseNumber( n, locale ) ).toBe( 2305843009213693696 );
application action="update" preciseMath=true;
expect( LSparseNumber( n, locale ) ).toBe( 2305843009213693952 ); // LSParseNumber doesn't support big numbers
});

} );
}

}
59 changes: 59 additions & 0 deletions test/functions/ParseNumber.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {
function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function afterAll(){
application action="update" precisemath=variables.preciseMath;
};

function run( testResults, testBox ){
describe( "Test ParseNumber", function(){

it( "Test with smaller number", function(){
var n = "2305843.44";
application action="update" preciseMath=false;
expect( parseNumber( n ) ).toBe( 2305843.44 );
application action="update" preciseMath=true;
expect( parseNumber( n ) ).toBe( 2305843.44 );
});

it( "Test with Large number", function(){
var n = "2305843009213693951.77";
application action="update" preciseMath=false;
expect( parseNumber( n ) ).toBe( 2305843009213693696 );
application action="update" preciseMath=true;
expect( parseNumber( n ) ).toBe( 2305843009213693951 ); // returns 2305843009213693951.77
});

it( "Test Bin", function(){
application action="update" preciseMath=false;
var n = "1000";
var radix = "bin";
expect( parseNumber( n, radix ) ).toBe( 8 );
application action="update" preciseMath=true;
expect( parseNumber( n, radix ) ).toBe( 8 );
});

it( "Test Oct", function(){
application action="update" preciseMath=false;
var n = "1000";
var radix = "oct";
expect( parseNumber( n, radix ) ).toBe( 512 );
application action="update" preciseMath=true;
expect( parseNumber( n, radix ) ).toBe( 512 );
});

it( "Test Hex", function(){
application action="update" preciseMath=false;
var n = "1000";
var radix = "hex";
expect( parseNumber( n, radix ) ).toBe( 4096 );
application action="update" preciseMath=true;
expect( parseNumber( n, radix ) ).toBe( 4096 );
});

} );
}

}
Loading