in reply to Re^2: Research into occasional participation in Perl/Raku development

in thread Research into occasional participation in Perl/Raku development

First up, I apologise for tainting this thread with that previous post of mine.

I need to keep in mind that raku was not written for me, but written for a group of people who find that raku suits them, and who are quite happy with what raku provides - and that I have no business complaining about anything that raku does.

I see just 2 ways to compare rationals and doubles:

1) convert the rational to a double and compare the two doubles;

or

2) convert the double to a rational and compare the two rationals.

The former is probably the easier, and that's the approach that raku takes.

But, in converting a rational to a double, it is often the case that precision is lost, and the double thus obtained is merely an approximation of the rational value from which it was derived.

OTOH, every finite double can be represented exactly as a rational - and it therefore makes sense to me that they should be compared via the latter option (like python3 does), as we are then always comparing exact values.

There's a caveat here in that the numerators/denominators needed to express some doubles can be rather large, and this could be viewed as a dis-incentive to using this second option.

Perl doesn't have a rational scalar, and C doesn't have a rational data type, so neither of those languages have needed to think about how rationals and floats should be compared.

(Of course, perl has a core Math::BigRat module in which the overloading of comparision operators needed to be considered.)

Cheers,

Rob

I need to keep in mind that raku was not written for me, but written for a group of people who find that raku suits them, and who are quite happy with what raku provides - and that I have no business complaining about anything that raku does.

*I think it just depends on which tool you use to get the job done.*I see just 2 ways to compare rationals and doubles:

1) convert the rational to a double and compare the two doubles;

or

2) convert the double to a rational and compare the two rationals.

The former is probably the easier, and that's the approach that raku takes.

But, in converting a rational to a double, it is often the case that precision is lost, and the double thus obtained is merely an approximation of the rational value from which it was derived.

OTOH, every finite double can be represented exactly as a rational - and it therefore makes sense to me that they should be compared via the latter option (like python3 does), as we are then always comparing exact values.

There's a caveat here in that the numerators/denominators needed to express some doubles can be rather large, and this could be viewed as a dis-incentive to using this second option.

Perl doesn't have a rational scalar, and C doesn't have a rational data type, so neither of those languages have needed to think about how rationals and floats should be compared.

(Of course, perl has a core Math::BigRat module in which the overloading of comparision operators needed to be considered.)

Cheers,

Rob

In Section
Meditations

Comment onRe^3: Research into occasional participation in Perl/Raku development