Control: tag -1 patch

On Fri, Nov 21, 2025 at 10:02:39PM +0100, Paul Gevers wrote:
> Source: libobject-pad-perl
> Version: 0.821-1
> Severity: serious
> Justification: ftbfs
> User: [email protected]
> Usertags: i386
> Control: -1 blocks 1118269

> The last upload of libobject-pad-perl failed to build on the buildds on
> i386.

> # Failed test 'class scope with import version 0.821 does not imply use
> strict'
> # at t/51pragmata.t line 27.
> # Code failed to compile - Global symbol "$def" requires explicit package
> name (did you forget to declare "my $def"?) at (eval 21) line 3.
> # Global symbol "$def" requires explicit package name (did you forget to
> declare "my $def"?) at (eval 21) line 3.

Hi, this seems to be a floating point precision thing specific to i386.

The following C test program shows it:

  #include <stdlib.h>
  #include <stdio.h>
  int main(void) {
        double d = strtod("0.821", NULL);
        printf("int(%.25f * 1000) ==\nint(  %.28f) ==\n      %d\n", d, 1000 * 
d, (int)(1000 * d));
  }

On amd64, the result is 821 as expected by the libobject-pad-perl code:

  int(0.8209999999999999520383653 * 1000) ==
  int(  821.0000000000000000000000000000) ==
        821
 
but in an i386 chroot on an amd64 host we get 820:

  int(0.8209999999999999520383653 * 1000) ==
  int(  821.0000000000000000000000000000) ==
        820
 
Not sure what to make of this, but the attached patch that applies
round(3) before casting to integer fixes it for me. Hopefully #including
<math.h> is acceptable upstream, but if not I'm sure they can come up
with something better.

Happy holidays,
-- 
Niko
>From 1da8e3d042207d7b8bba623c174440c18f27f95f Mon Sep 17 00:00:00 2001
From: Niko Tyni <[email protected]>
Date: Sun, 28 Dec 2025 18:00:15 +0000
Subject: [PATCH] Fix floating point handling in version comparison

(int)(1000 * strtod("0.821")) can result in 820 due to floating point
rounding errors.

Bug-Debian: https://bugs.debian.org/1121148

Bug: https://rt.cpan.org/Ticket/Display.html?id=170231
---
 lib/Object/Pad.xs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/Object/Pad.xs b/lib/Object/Pad.xs
index 7490122..8ea1620 100644
--- a/lib/Object/Pad.xs
+++ b/lib/Object/Pad.xs
@@ -8,6 +8,7 @@
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
+#include <math.h>
 
 #include "XSParseKeyword.h"
 
@@ -437,7 +438,7 @@ static int build_classlike(pTHX_ OP **out, XSParseKeywordPiece *args[], size_t n
     SV **svp;
     if(hints &&
         (svp = hv_fetchs(hints, "Object::Pad/imported-version", 0)))
-      imported_version = SvNV(*svp) * 1000;
+      imported_version = round(SvNV(*svp) * 1000);
   }
 
   bool is_anon = false;
-- 
2.51.0

Reply via email to