[latex3-commits] [latex3/latex3] main: Correct a rare bug when rounding division (fixes #1264) (a7b2765c4)

github at latex-project.org github at latex-project.org
Sun Oct 8 17:27:21 CEST 2023


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/a7b2765c4ae2f1d84c8ceefe8a37f7bfa2ccac61

>---------------------------------------------------------------

commit a7b2765c4ae2f1d84c8ceefe8a37f7bfa2ccac61
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Sun Oct 8 17:27:21 2023 +0200

    Correct a rare bug when rounding division (fixes #1264)
    
    This bug would occur at most every 20000 divisions or so.


>---------------------------------------------------------------

a7b2765c4ae2f1d84c8ceefe8a37f7bfa2ccac61
 l3kernel/CHANGELOG.md                 | 3 +++
 l3kernel/l3fp-basics.dtx              | 6 +++---
 l3kernel/testfiles/m3fp-basics003.lvt | 2 ++
 l3kernel/testfiles/m3fp-basics003.tlg | 2 ++
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index a176d757a..d291fd3ca 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -21,6 +21,9 @@ this project uses date-based 'snapshot' version identifiers.
 - Standardise variants for `\prop_(g)put_if_new:Nnn`
 - Standardise variants for `\prop_(g)remove:Nn`
 
+### Fixed
+- Rare rounding error in divisions (issue \#1264)
+
 ## [2023-08-29]
 
 ### Added
diff --git a/l3kernel/l3fp-basics.dtx b/l3kernel/l3fp-basics.dtx
index 6a8d6376f..aa9854343 100644
--- a/l3kernel/l3fp-basics.dtx
+++ b/l3kernel/l3fp-basics.dtx
@@ -1429,11 +1429,11 @@
   {
     + 5 * #1
     \exp_after:wN \@@_div_significand_vi:Nw
-    \int_value:w \@@_int_eval:w -20 + 2*#2#3 - #1*#6#7 +
+    \int_value:w \@@_int_eval:w -50 + 2*#2#3 - #1*#6#7 +
       \exp_after:wN \@@_div_significand_v:NN
-      \int_value:w \@@_int_eval:w 199980 + 2*#4 - #1*#8 +
+      \int_value:w \@@_int_eval:w 499950 + 2*#4 - #1*#8 +
         \exp_after:wN \@@_div_significand_v:NN
-        \int_value:w \@@_int_eval:w 200000 + 2*#5 - #1*#9 ;
+        \int_value:w \@@_int_eval:w 500000 + 2*#5 - #1*#9 ;
   }
 \cs_new:Npn \@@_div_significand_v:NN #1#2 { #1#2 \@@_int_eval_end: + }
 \cs_new:Npn \@@_div_significand_vi:Nw #1#2;
diff --git a/l3kernel/testfiles/m3fp-basics003.lvt b/l3kernel/testfiles/m3fp-basics003.lvt
index c3fa2488b..a952e86ff 100644
--- a/l3kernel/testfiles/m3fp-basics003.lvt
+++ b/l3kernel/testfiles/m3fp-basics003.lvt
@@ -87,6 +87,8 @@
   \test:nn {13579238576348} {23573948576428} \NEWLINE
   \test:nn {21342.39876238473423} {.9384123239423948238} \NEWLINE
   \test:nn {912392184728736423847} {32324234234325234123124} \NEWLINE
+  \test:nn {8000000854999998}{1000000099999999} \NEWLINE
+  \test:nn {0.8}{10.00000000009} \NEWLINE
 }
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/l3kernel/testfiles/m3fp-basics003.tlg b/l3kernel/testfiles/m3fp-basics003.tlg
index 7f5bf44d8..628a8782b 100644
--- a/l3kernel/testfiles/m3fp-basics003.tlg
+++ b/l3kernel/testfiles/m3fp-basics003.tlg
@@ -134,4 +134,6 @@ TEST 2: Division
 0.5760273266196108
 22743.09300705097
 0.02822625829631762
+8.000000055000001
+0.07999999999928
 ============================================================





More information about the latex3-commits mailing list.