-
Notifications
You must be signed in to change notification settings - Fork 0
Numerical operators in Perl 6
James E Keenan edited this page Feb 7, 2016
·
1 revision
$ cat numerical_operators.pl6
#!/usr/bin/env perl6
say "Infix numerical operators with numerical result";
say "addition: 3 + 2 : ", 3 + 2;
say "subtraction: 17 - 34 : ", 17 - 34;
say "multiplication: 4 * 2 : ", 4 * 2;
say "division: 10 / 3 : ", 10 / 3;
say "power: 4 ** 2 : ", 4 ** 2;
say "integer division: 10 div 3 : ", 10 div 3;
say "modulo: 10 % 3 : ", 10 % 3;
say "greatest common";
say " denominator: 75 gcd 20 : ", 75 gcd 20;
say "least common";
say " multiple: 75 lcm 20 : ", 75 lcm 20;
say "";
say "Infix numerical operators with boolean result";
say "divisibility: 6 %% 4 : ", 6 %% 4;
say "divisibility: 6 %% 3 : ", 6 %% 3;
say "equal: 7 == 6 : ", 7 == 6;
say "not equal: 7 != 7 : ", 7 != 7;
say "less than: 7 < 10 : ", 7 < 10;
say "less than or equal: 7 <= 10 : ", 7 <= 10;
say "greater than: 5 > 8 : ", 5 > 8;
say "greater than or equal: 5 >= 8 : ", 5 >= 8;
Output:
$ perl6 numerical_operators.pl6
Infix numerical operators with numerical result
addition: 3 + 2 : 5
subtraction: 17 - 34 : -17
multiplication: 4 * 2 : 8
division: 10 / 3 : 3.333333
power: 4 ** 2 : 16
integer division: 10 div 3 : 3
modulo: 10 % 3 : 1
greatest common
denominator: 75 gcd 20 : 5
least common
multiple: 75 lcm 20 : 300
Infix numerical operators with boolean result
divisibility: 6 %% 4 : False
divisibility: 6 %% 3 : True
equal: 7 == 6 : False
not equal: 7 != 7 : False
less than: 7 < 10 : True
less than or equal: 7 <= 10 : True
greater than: 5 > 8 : False
greater than or equal: 5 >= 8 : False