develooper Front page | perl.perl5.porters | Postings from August 2017

Re: Revisiting smart match

Thread Previous | Thread Next
From:
Zefram
Date:
August 3, 2017 00:10
Subject:
Re: Revisiting smart match
Message ID:
20170803001021.GE9383@fysh.org
Father Chrysostomos wrote:
>It is less arbitrary, because it is more versatile.  You can do
>'0+$x eq 0+$y', but you cannot use == for string comparison.

That formulation doesn't perform ==-like numeric comparison:

$ perl -MData::Float=nextup -lwe 'print nextup(1) == 1 ? "yes" : "no"; print 0+nextup(1) eq 0+1 ? "yes" : "no"'
no
yes

Stringification would have to provide two more decimal digits to
render each floating point value as a distinct string.  Nor is this
performing a coherent approximate comparison, of the type sometimes
wanted with floating point: some adjacent floating point values have
distinct stringifications, so will compare unequal.  The kind of
comparison performed via stringification has all the downsides of ==
on floating point values, but operates with reduced precision and larger
discontinuities of relative precision.

-zefram

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About