FAQ
Author: lwall
Date: 2009-07-18 18:44:26 +0200 (Sat, 18 Jul 2009)
New Revision: 27605

Modified:
docs/Perl6/Spec/S32-setting-library/Numeric.pod
Log:
[Numeric] kill :Trig tag, always include trig functions.
Replace stupid string args with an enum.
Default to lexical constant $?TRIGBASE.


Modified: docs/Perl6/Spec/S32-setting-library/Numeric.pod
===================================================================
--- docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-07-18 14:42:37 UTC (rev 27604)
+++ docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-07-18 16:44:26 UTC (rev 27605)
@@ -19,8 +19,8 @@

Created: 19 Mar 2009 extracted from S29-functions.pod

- Last Modified: 19 Feb 2009
- Version: 1
+ Last Modified: 18 Jul 2009
+ Version: 2

The document is a draft.

@@ -228,16 +228,19 @@

=back

-=head2 The :Trig tag
+=head2 Trigonometric functions

-The following are also defined in C<Num> but not exported without a C<:Trig>
-tag. (Which installs their names into C<Num::Trig>, as it happens.)
+The following are also defined in C<Num>. The trig functions
+depend on the current (lexically scoped) trig base:

+ enum TrigBase is export <Radians Degrees Gradians Circles>;
+ constant $?TRIGBASE = Radians;
+
=over 4

=item I<Standard Trig Functions>

- Num multi method func ( Num $x: $base = 'radians' ) is export(:Trig)
+ Num multi method func ( Num $x: TrigBase $base = $?TRIGBASE ) is export

where I<func> is one of:
sin, cos, tan, asin, acos, atan, sec, cosec, cotan, asec, acosec,
@@ -249,20 +252,18 @@
Option C<$base> is used to declare how you measure your angles.
Given the value of an arc representing a single full revolution.

- $base Result
- ---- -------
- /:i ^r/ Radians (2*pi)
- /:i ^d/ Degrees (360)
- /:i ^g/ Gradians (400)
- Num Units of 1 revolution.
+ $base Subdivisions of circle
+ ---- ----------------------
+ Radians 2*pi
+ Degrees 360
+ Gradians 400
+ Circles 1

-Note that module currying can be used within a lexical scope to specify
-a consistent base so you don't have to supply it with every call:
+To change the base within your own lexical scope, it suffices to redefine the
+compiler constant:

- my module Trig ::= Num::Trig.assuming(:base<degrees>);
+ constant $?TRIGBASE = Degrees;

-This overrides the default of "radians".
-
=item atan2

our Num multi method atan2 ( Num $y: Num $x = 1 )
@@ -277,3 +278,5 @@

Please post errors and feedback to perl6-language. If you are making
a general laundry list, please separate messages by topic.
+
+=for vim:set expandtab sw=4:

Search Discussions

  • James Cloos at Jul 19, 2009 at 3:13 am
    lwall> + enum TrigBase is export <Radians Degrees Gradians Circles>;

    Is Circles of much value?

    I can see Semicircles, since that would make the range (-1,1] or [-1,1).
    But a range of [0,1) or (0,1] seems *much* less useful.

    Or am I missing an obvious use case?

    -JimC
    --
    James Cloos <cloos@jhcloos.com> OpenPGP: 1024D/ED7DAEA6
  • Geoffrey Broadwell at Jul 19, 2009 at 6:03 pm

    On Sat, 2009-07-18 at 21:22 -0400, James Cloos wrote:
    lwall> + enum TrigBase is export <Radians Degrees Gradians Circles>;

    Is Circles of much value?

    I can see Semicircles, since that would make the range (-1,1] or [-1,1).
    But a range of [0,1) or (0,1] seems *much* less useful.

    Or am I missing an obvious use case?
    With Circles, simple int/frac always gets you a count of full rotations
    and an angle always between 0 and one full rotation. Seems useful to
    me.

    Semicircles sounds useful as well, for the reason you state above.


    -'f

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl6-language @
categoriesperl
postedJul 18, '09 at 4:44p
activeJul 19, '09 at 6:03p
posts3
users3
websiteperl6.org

People

Translate

site design / logo © 2021 Grokbase