in reply to Windows / Linux puzzler

I can't spot the exact problem but I suspect a floating point problem. I suggest you follow the advice from perldoc int and use the POSIX::floor instead:

From the docs:

...For example, int(-6.725/0.025) produces -268 rather than the correct -269; that's because it's really more like -268.99999999999994315658 instead. Usually, the sprintf, printf, or the POSIX::floor and POSIX::ceil functions will serve you better than will int.

Replies are listed 'Best First'.
Re^2: Windows / Linux puzzler
by lbrandewie (Acolyte) on Mar 23, 2020 at 20:32 UTC

    Hmmmmmmmmmmmmmmmmmmmm...

      Hmmmmmmmmmmmmmmmmmmmm...

      I think Veltro's point is likely irrelevant if both the Windows perl and Linux perl report the same value for $Config{nvsize}.
      But if the nvsize differs between the 2 perls, then it's a different matter. For example:
      On perl-5.30.0 whose nvsize is 8 (and whose nvtype is 'double': C:\>perl -V:nvsize nvsize='8'; C:\>perl -le "print int(1000 * 0.001);" 1 On perl-5.30.0 whose nvsize is 12 or 16 (and whose nvtype is 'long dou +ble'): C:\>perl -V:nvsize nvsize='16'; C:\>perl -le "print int(1000 * 0.001);" 0
      Does perl -V:nvsize report the same value on both machines ?
      Does perl -V:nvtype report the same type on both machines ?

      Update:
      It's probably worth mentioning that both of those perls are correct in what they're doing.
      The double that most closely represents the value 0.001 is actually slightly greater than 0.001
      The long double that most closely represents the value 0.001 is actually slightly less than 0.001.

      Cheers,
      Rob

        I think Veltro's point is likely irrelevant if both the Windows perl and Linux perl report the same value for $Config{nvsize}.

        In at least some verisons of Perl, creating a float from a string is done by the underlying C library, and MS's library is known to not be as good as a gcc's.

        Image showing the output varies by compiler

        I didn't include nvsize in the screenshot, but both builds use IEEE double-precision floats.

        Hey Rob,

        Thanks for the reply. Both versions of perl report nvsize at 8. But, I have no clue what the significance of this value is. Could you please explain?

        Thanks,

        Lars