@@ -29,7 +29,7 @@ tightest to loosest:
29
29
X Junctive or | ^
30
30
L Named unary temp let
31
31
N Structural infix but does <=> leg cmp .. ..^ ^.. ^..^
32
- C Chaining infix != == < <= > >= eq ne lt le gt ge ~~ === eqv !eqv
32
+ C Chaining infix != == < <= > >= eq ne lt le gt ge ~~ === eqv !eqv =~=
33
33
X Tight and &&
34
34
X Tight or || ^^ // min max
35
35
R Conditional ?? !! ff fff
@@ -1392,6 +1392,45 @@ Here is an excerpt of built-in smart-matching functionality:
1392
1392
1393
1393
= end table
1394
1394
1395
+ = head2 infix C « =~= »
1396
+
1397
+ proto sub infix:<=~=>($, $) returns Bool:D is assoc:<chain>
1398
+ multi sub infix:<=~=>(Any, Any)
1399
+ multi sub infix:<=~=>(Int:D, Int:D)
1400
+ multi sub infix:<=~=>(Num:D, Num:D)
1401
+ multi sub infix:<=~=>(Rational:D, Rational:D)
1402
+ multi sub infix:<=~=>(Real:D, Real:D)
1403
+ multi sub infix:<=~=>(Complex:D, Complex:D)
1404
+ multi sub infix:<=~=>(Numeric:D, Numeric:D)
1405
+
1406
+ The X < approximately-equal operator > . Calculates the relative difference between
1407
+ the left-hand and right-hand sides and returns C < True > if the difference is
1408
+ less than $*TOLERANCE (which defaults to 1e-15). However, if either side is zero
1409
+ then it checks that the absolute difference between the sides is less than $*TOLERANCE.
1410
+ Note that this operator is not arithmetically symetrical (doesn't do ± Δ):
1411
+
1412
+ say ($x + $*TOLERANCE) =~= $x; # True
1413
+ say ($x - $*TOLERANCE) =~= $x; # False
1414
+
1415
+ The tolerance is supposed to be modifiable via an adverb:
1416
+
1417
+ say $x =~= $y :tolerance(.1);
1418
+
1419
+ however, this is not yet implemented. The same effect can be achieved by
1420
+ assigning to $*TOLERANCE.
1421
+
1422
+ {
1423
+ my $*TOLERANCE = .1;
1424
+ say 11 =~= 10; # True
1425
+ }
1426
+
1427
+ Note that setting $*TOLERANCE = 0 will cause all comparisons to fail.
1428
+
1429
+ {
1430
+ my $*TOLERANCE = 0;
1431
+ say 1 =~= 1; # False
1432
+ }
1433
+
1395
1434
= head1 Tight AND Precedence
1396
1435
1397
1436
= head2 infix C « && »
0 commit comments