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

Re: Revisiting smart match

Thread Previous | Thread Next
August 3, 2017 00:10
Re: Revisiting smart match
Message ID:
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"'

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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About