Regression: BitXor,BitSHRN,BitSHLN return wrong answer when preciseMath is default and then toggled

Description

Found this while updating the tests to test both preciseMath true and false, toggling via the application tag

If preciseMath is enabled system wide, this works, if it’s disabled, it returns the wrong result?

<cfscript> dump(getApplicationSettings().preciseMath, true); application action="update" preciseMath=false; dump(getApplicationSettings().preciseMath, true); x = BitXOr("18446744073709551615", "1") & ""; res = "9223372036854775807"; dump(getApplicationSettings().preciseMath, true); if (x eq res) dump("ok") else { dump("error, expected"); dump("#res#"); dump("----got "); dump("#x#"); } echo("<hr>"); dump("enableprecise math"); application action="update" preciseMath=true; dump(getApplicationSettings().preciseMath, true); x = BitXOr("18446744073709551615", "1") & ""; res= "18446744073709551614"; dump(getApplicationSettings().preciseMath, true); if (x eq res) dump("ok") else { dump("error, expected"); dump("#res#"); dump("----got "); dump("#x#"); } </cfscript>

with presideMath=true in the admin

 

image-20241204-155942.png

but when false in the admin

 

image-20241204-160020.png

 

Environment

None

Attachments

3
  • 04 Dec 2024, 04:01 pm
  • 04 Dec 2024, 04:01 pm
  • 04 Dec 2024, 04:01 pm

Activity

Show:

Pothys - MitrahSoft 17 December 2024 at 15:12

, I tested this ticket with Lucee version 6.2.0.218-SNAPSHOT. When I checked BitXor(), BitSHRN(), and BitSHLN() with the updated test cases. It returned the expected results and now its works fine.

Pothys - MitrahSoft 12 December 2024 at 08:13

, I have investigated this ticket using Lucee version 6.2.0.205-SNAPSHOT.
When I ran the test cases with "Precise Math" set to false in the admin panel, it returned an unexpected value.
The BitXor() function requires an integer value, but in this case, it is being used with a big integer.
Below is the test code for the BitXor() function with a big integer. It returns the expected value when "Precise Math" is set to false in the admin panel. However, the issue still occurs in the latest version.

<cfscript> application action="update" preciseMath=true; bigInt = createObject("java", "java.math.BigInteger"); a = bigInt.init("18446744073709551615"); dump(BitXOr(a, "1")); </cfscript>

Michael Offner 10 December 2024 at 09:19

improved test cases that failed. BitSHRN did start with a value that was outside of the range of double.

 

https://github.com/lucee/Lucee/commit/015e2caf7bd92fb31063edea00c672f47cad1fab

Michael Offner 10 December 2024 at 09:12

with BitSHLN.cfc you simply have an overflow of the double as you can see running this

<cfscript> application action="update" preciseMath=true; loop from=1 to=64 index="i" { dump(label:i, var:BitSHLN(1, i)); // 1 << 64 = 0 (all bits shifted out in a 64-bit context) } application action="update" preciseMath=false; loop from=1 to=64 index="i" { dump(label:i, var:BitSHLN(1, i)); // 1 << 64 = 0 (all bits shifted out in a 64-bit context) } </cfscript>

i will adjust the test case

Michael Offner 9 December 2024 at 22:11

most likely this is because the value need to be converted from double to bigDecimal in this case and looses perciscion in the process, this is a edge case.

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Created 4 December 2024 at 16:01
Updated 15 March 2025 at 14:01
Resolved 17 December 2024 at 15:13

Flag notifications