Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bif_abs, bif_complex_re, and bif_complex_im, typing them to prefi…
…x:<abs>, Complex.re, and Complex.im respectively. Error conditions for big_complex_re and bif_complex_im applied to non-complex objects are wrong, but I'm not sure if that can ever come into play in practice. Also added abs_test.pl with quick tests of these methods.
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# vim: ft=perl6 | ||
|
||
use Test; | ||
|
||
plan 17; | ||
|
||
is 10.abs, 10, "10.abs == 10"; | ||
is (-10).abs, 10, "(-10).abs == 10"; | ||
is (-10).abs.WHAT, 10.WHAT, "(-10).abs and 10 have same WHAT"; | ||
|
||
{ | ||
my $big = 2 ** 200 - 42; | ||
is $big.abs, $big, '$big.abs == $big'; | ||
is (-$big).abs, $big, '(-$big).abs == $big'; | ||
is (-$big).abs.WHAT, $big.WHAT, '(-$bi).abs and $big have same WHAT'; | ||
} | ||
|
||
ok (10/2).abs == 10/2, "(10/2).abs == 10/2"; | ||
ok (-10/2).abs == 10/2, "(-10/2).abs == 10/2"; | ||
is (-10/2).abs.WHAT, (10/2).WHAT, "(-10/2).abs and 10/2 have same WHAT"; | ||
|
||
ok (10.Num).abs == 10.Num, "(10.Num).abs == 10.Num"; | ||
ok (-10.Num).abs == 10.Num, "(-10.Num).abs == 10.Num"; | ||
is (-10.Num).abs.WHAT, (10.Num).WHAT, "(-10.Num).abs and 10.Num have same WHAT"; | ||
|
||
ok (10 + 5i).abs == 125.sqrt, "(10 + 5i).abs == 125.sqrt"; | ||
ok (-10 - 5i).abs == 125.sqrt, "(-10 - 5i).abs == 125.sqrt"; | ||
is (-10 - 5i).abs.WHAT, "Num()", "(-10 - 5i).abs is a Num"; | ||
|
||
ok (10 + 5i).re == 10, "(10 + 5i).re == 10"; | ||
ok (10 + 5i).im == 5, "(10 + 5i).im == 5"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters