I have written a fairly complex Perl-Tk application that runs fine on Linux, FreeBSD and on Intel Macs (using MacPorts Perl-Tk).

But on Macs based on M1/M2 cpu (again using MacPorts Perl-Tk) simple floating point arithmetics fail to return the correct result, instead the floating point parts of the operands are ignored and the result is calculated like if it was integer numbers.

For example on Linux and Intel Mac 12.99 * 16.25 returns 211.0875, which is correct, but on M1/M2 Macs with MacPorts Perl I get 192, so Perl is simply doing 12 * 16, completely ignoring the decimals.

I have written a small Perl-Tk script that reproduces this problem (this is really an extract from my application that's why it might look unnecessarily convoluted):
#!/usr/bin/env perl use strict; use warnings; use POSIX qw(strftime); use Tk; my %pid=( DCDC_A_51=>{cmd=>'22 46 5B', cu=>'51', desc=>'DC/DC output curren +t t30', unit=>'A', d=>2, formula=>'sprintf("%.2f", U16(1 +,4)/16)'}, DCDC_V_51=>{cmd=>'22 46 5C', cu=>'51', desc=>'DC/DC output voltag +e t30', unit=>'V', d=>2, formula=>'sprintf("%.2f", U16(2 +5,253)/512)', val=>'---'}, DCDC_W_51=>{ desc=>'DC/DC power output' +, unit=>'W', action=>'sprintf("%.0f", ($pid +{DCDC_V_51}{val} * $pid{DCDC_A_51}{val}))', val=>'---'} ); my $mw=MainWindow->new(); $mw->Button(-text=>" Test ", -command=>sub{test()}, -font=>'Helvet +ica 18 bold', -pady=>20)->pack(); MainLoop; sub test { $pid{DCDC_V_51}{val}=eval($pid{DCDC_V_51}{formula}); print $pid{DCDC_V +_51}{val} ."\n"; $pid{DCDC_A_51}{val}=eval($pid{DCDC_A_51}{formula}); print $pid{DCDC_A +_51}{val} ."\n"; my $formula=$pid{DCDC_W_51}{action}; $pid{DCDC_W_51}{val}=eval($formula); print $pid{DCDC_W_51}{val} ."\n"; } sub U16 { my($a,$b)=@_; return ($a*256+$b); }
This test program can also be downloaded from my website at the following URL: http://obd-amigos.linuxtech.net/test1/amigos-test1.pl

Is there anybody here who uses MacPorts Perl on a M1/M2 Mac who can reproduce this issue with the above test script and perhaps has an idea why this happens?
I'm thinking of opening a bug report at MacPorts but would prefer to first get some feedback here in case it's not a MacPorts issue.
Thanks in advance for any testing / feedback / opinions / insights.

Edit: changed "use POSIX;" to "use POSIX qw(strftime);" in the test script.

In reply to weird problem with macports perl on apple m1/m2 based system by perltux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.