in reply to Re: Getting stranger values in subtraction
in thread Getting stranger values in subtraction

Please explain why language makes a difference. All the references given so far suggest that it should not.
Bill
  • Comment on Re^2: Getting stranger values in subtraction

Replies are listed 'Best First'.
Re^3: Getting stranger values in subtraction
by Laurent_R (Canon) on Feb 06, 2016 at 15:04 UTC
    Hi Bill,

    Perl 6 is converting fractional numbers not into floating-point numbers as most languages, but into Rat (rational) type values. Internally, rational type numbers are in fact made of pairs of integer numbers, one for the numerator and one for the denominator, stored separately. So the numeric literal 319.02 is stored internally as something like (numerator = 31902, denominator = 100). When making arithmetic operations on such numbers, Perl 6 will happily add (or subtract) the integers and then print the result as a rational number. The result is accurate because there is no use of floating-point number approximation.

    Consider the following code introspecting the types of values and variables:

    > say 42.WHAT; (Int) > say 319.02.WHAT; (Rat) > say $x.WHAT; (Rat)