You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Language/numerics.pod6
+31-25Lines changed: 31 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -275,7 +275,7 @@ L<Failure>, while L<Complex> division by zero produces C<NaN> components,
275
275
regardlesss of what the numerator is.
276
276
277
277
As of 6.d language, both L<Num> and L<Complex> division by zero will produce
278
-
a L<-Inf>, L<+Inf>, or L<NaN> depending on whether the numerator was negative, positive, or zero, respectively (for L<Complex> the real and imaginary
278
+
a -L<Inf|/type/Num#Inf>, C<+Inf>, or L<NaN> depending on whether the numerator was negative, positive, or zero, respectively (for L<Complex> the real and imaginary
279
279
components are L<Num> and are considered separately).
280
280
281
281
Division of L<Int> numerics produces a L<Rat> object (or a L<Num>, if
@@ -553,9 +553,10 @@ say my uint8 @a = 1000, 2000, 3000; # OUTPUT: «232 208 184»
553
553
554
554
=head2Auto-Boxing
555
555
556
-
While they can be referred to as "native I<types>", native numerics are not actually classes
557
-
that have any sort of methods available. However, you I<can> call any of the methods available
558
-
on non-native versions of these numerics. What's going on?
556
+
While they can be referred to as "native I<types>", native numerics are not
557
+
actually classes that have any sort of methods available. However, you I<can>
558
+
call any of the methods available on non-native versions of these numerics.
559
+
What's going on?
559
560
560
561
=begincode
561
562
my int8 $x = -42;
@@ -595,10 +596,11 @@ my int $a-native = -42;
595
596
596
597
=head2Default Values
597
598
598
-
Since there are no classes behind native types, there are no type objects you'd normally get
599
-
with variables that haven't been initialized. Thus, native types are automatically initialized
600
-
to zero. In 6.c language, native floating point types (C<num>, C<num32>, and C<num64>) are
601
-
initialized to value C<NaN>; it is proposed for default to become C<0e0> in 6.d language.
599
+
Since there are no classes behind native types, there are no type objects you'd
600
+
normally get with variables that haven't been initialized. Thus, native types
601
+
are automatically initialized to zero. In 6.c language, native floating point
602
+
types (C<num>, C<num32>, and C<num64>) are initialized to value C<NaN>; it is
603
+
proposed for default to become C<0e0> in 6.d language.
602
604
603
605
=head2Native Dispatch
604
606
@@ -656,26 +658,30 @@ say f $x;
656
658
# in block <unit> at -e line 1
657
659
=endcode
658
660
659
-
However, this rule is waived if a call is being made where one of the arguments is a native type
660
-
and another one is a L<numeric literal>:
661
+
However, this rule is waived if a call is being made where one of the arguments
662
+
is a native type and another one is a
663
+
L<numeric literal|/syntax/Number literals>:
661
664
662
665
=begincode
663
666
multi f(int, int) {}
664
667
f 42, my int $x; # Successfull call
665
668
=endcode
666
669
667
-
This way you do not have to constantly write, for example, C«$n +> 2» as C«$n +> (my int $ = 2)».
668
-
The compiler knows the literal is small enough to fit to a native type and converts it to a native.
670
+
This way you do not have to constantly write, for example, C«$n +> 2» as C«$n +>
671
+
(my int $ = 2)». The compiler knows the literal is small enough to fit to a
672
+
native type and converts it to a native.
669
673
670
674
=head2Atomic Operations
671
675
672
676
The language offers L<some operations|https://docs.perl6.org/type/atomicint>
673
677
that are guaranteed to be performed atomically, i.e. safe to be executed
674
678
by multiple threads without the need for locking with no risk of data races.
675
679
676
-
For such operations, the L<atomicint> native type is required. This type is
677
-
similar to a plain native L<int>, except it is sized such that CPU-provided atomic operations can be performed upon it. On a 32-bit CPU it will typically
678
-
be 32 bits in size, and on an a 64-bit CPU it will typically be 64 bits in size.
680
+
For such operations, the L<atomicint|/type/atomicint> native type is required.
681
+
This type is similar to a plain native L<int|/type/int>, except it is sized such
682
+
that CPU-provided atomic operations can be performed upon it. On a 32-bit CPU it
683
+
will typically be 32 bits in size, and on an a 64-bit CPU it will typically be
684
+
64 bits in size.
679
685
680
686
=begincode
681
687
# !!WRONG!! Might be non-atomic on some systems
@@ -696,23 +702,23 @@ multi-dispatch.
696
702
697
703
=head1Numeric Infectiousness
698
704
699
-
Numeric "infectiousness" dictates the resultant type when two numerics of different types are
700
-
involved in some mathematical operations. A type is said to be more infectious than the other type
701
-
if the result is of that type rather than the type of the other operand. For example, L<Num>
702
-
type is more infectious than an L<Int>, thus we can expect C<42e0 + 42> to produce a L<Num> as the
703
-
result.
705
+
Numeric "infectiousness" dictates the resultant type when two numerics of
706
+
different types are involved in some mathematical operations. A type is said to
707
+
be more infectious than the other type if the result is of that type rather than
708
+
the type of the other operand. For example, L<Num> type is more infectious than
709
+
an L<Int>, thus we can expect C<42e0 + 42> to produce a L<Num> as the result.
704
710
705
711
The infectiousness is as follows, with the most infectious type listed first:
706
712
707
-
=item* Complex
713
+
=itemComplex
708
714
709
-
=item* Num
715
+
=itemNum
710
716
711
-
=item* FatRat
717
+
=itemFatRat
712
718
713
-
=item* Rat
719
+
=itemRat
714
720
715
-
=item* Int
721
+
=itemInt
716
722
717
723
=begincode
718
724
say (2 + 2e0).^name; # Int + Num => OUTPUT: «Num»
0 commit comments