@@ -20,8 +20,8 @@ DRAFT: Synopsis 32: Setting Library - Numeric
20
20
21
21
Created: 19 Mar 2009 extracted from S29-functions.pod
22
22
23
- Last Modified: 28 June 2011
24
- Version: 11
23
+ Last Modified: 6 Jan 2012
24
+ Version: 12
25
25
26
26
The document is a draft.
27
27
@@ -340,7 +340,7 @@ C<Num> is a machine-precision numeric real value.
340
340
C<Complex> is an immutable type. Each C<Complex> object stores two numbers,
341
341
the real and imaginary part. For all practical purposes a C<Complex> with
342
342
a C<NaN> in real or imaginary part may be considered a C<NaN> itself (and
343
- C<(NaN + 1i) ~~ NaN> is C<True>).
343
+ C<(NaN+ 1i) ~~ NaN> is C<True>).
344
344
345
345
Coercion of a C<Complex> to any C<Real> returns the real part (coerced, if
346
346
necessary) if the imaginary part is 0, and fails otherwise. Comparison
@@ -354,7 +354,8 @@ the C<Complex> to a real number blindly.
354
354
our Complex multi method new(Real $re, Real $im)
355
355
356
356
Constructs a C<Complex> number from real and imaginary part. This is the
357
- method form of C<$re + ($im)i>.
357
+ method form of C<$re+$im\i>. (But use the C<< <1+2i> >> form for literals,
358
+ so that you don't have to worry about precedence or rely on constant folding.)
358
359
359
360
=item polar
360
361
@@ -375,6 +376,22 @@ Returns the real part of the complex number.
375
376
376
377
Returns the imaginary part of a complex number.
377
378
379
+ =item gist
380
+
381
+ our Str multi method gist()
382
+
383
+ Returns a string representation of the form "C<1+2i>", without
384
+ internal spaces. (C<Str> coercion also returns this.)
385
+
386
+ =item perl
387
+
388
+ our Str multi method perl()
389
+
390
+ Returns a string representation corresponding to the unambiguous
391
+ C<val()>-based representation of complex literals, of the form "C<< <1+2i> >>",
392
+ without internal spaces, and including the angles that keep the C<+>
393
+ from being treated as a normal addition operator.
394
+
378
395
=back
379
396
380
397
=head2 Trigonometric functions
@@ -464,32 +481,58 @@ denominator were stored in a normal form: both numerator and denominator are
464
481
minimal in their magnitude, and the denominator is positive. So
465
482
C<Rat.new(2, -4).denominator> return C<2>, because the normal form is C<-1/2>.
466
483
484
+ (An implementation is allowed to be lazy about this internally when it
485
+ determines that normalizing repeatedly is detrimental to performance,
486
+ such as when adding a column of numbers that all have an internal
487
+ denominator of 100.)
488
+
467
489
=over
468
490
469
491
=item new
470
492
471
493
multi method new(Int $num, Int $denom)
472
494
473
495
Constructs a C<Rat> object from the numerator and denominator.
474
- Fails if C<$denom == 0>.
496
+ Fails if C<$denom == 0>. You can use division to produce a C<Rat>
497
+ through constant folding, but generally if you know the values in
498
+ advance, you should use one of literal forms so that you don't have to
499
+ rely on precedence. You may use the C<val()>-based C<< <3/5> >> form,
500
+ or you can simply write decimal numbers with a decimal point, since
501
+ C<12.34> is essentially identical to C<< <1234/100> >> as a literal.
475
502
476
503
=item nude
477
504
478
505
our Seq[Int] multi method nude()
479
506
480
- Returns a C<Seq> of numerator and denominator
507
+ Returns a C<Seq> of numerator and denominator.
481
508
482
509
=item denominator
483
510
484
511
our Int multi method denominator()
485
512
486
- Returns the denominator
513
+ Returns the denominator.
487
514
488
515
=item numerator
489
516
490
517
our Int multi method numerator()
491
518
492
- Returns the numerator
519
+ Returns the numerator.
520
+
521
+ =item gist
522
+
523
+ our Str multi method gist()
524
+
525
+ Returns a string representation by first converting to C<Num> and then using the normal decimal
526
+ output of that type. (C<Str> coercion also does this.)
527
+
528
+ =item perl
529
+
530
+ our Str multi method perl()
531
+
532
+ Returns a string representation corresponding to the unambiguous
533
+ C<val()>-based representation of complex literals, of the form "C<< <3/5> >>",
534
+ without internal spaces, and including the angles that keep the C</>
535
+ from being treated as a normal division operator.
493
536
494
537
=back
495
538
0 commit comments