Re: r29111 - docs/Perl6/Spec
Acknowledging that 'FatRat' is current name for above 'Ratio' ... pugs-comm...@feather.perl6.nl wrote: -For applications that really need arbitrary precision denominators -as well as numerators, CRatio may be used, which is defined as CInt/Int. +For applications that really need arbitrary precision denominators as +well as numerators at the cost of performance, CRatio may be used, +which is stored as CInt/Int, that is, as arbitrary precision in +both parts. There is no literal form for a CRatio, so it must +be constructed using CRatio.new($nu,$de). In general, only math +operators with at least one CRatio argument will return another +CRatio, to prevent accidental promotion of reasonably fast CRat +values into arbitrarily slow CRatio values. Given the above, if one wants to construct a full-precision rational value in terms of 3 Int values analogous to a mantissa and radix and exponent, what is the best way to write it in Perl 6? For example, say I want the following expression to result in a FatRat because presumably that's the only type which will represent the result value exactly: 45207196 * 10 ** -37 How should that be spelled out in terms of 3 integers? And note that a decimal-specific answer isn't what I want, since I want something that would also work for this: 45207196 * 11 ** -37 Any thoughts? Basically where I'm coming from here is the idea that any rational can also be expressed as 3 integers like the above, not just the numerator/denominator pair; the 3 integers are advantages both for being efficient with common pathological cases such as very large or very small rationals with a small amount of precision, such as the above, as well as for exactly reflecting the concept of a radix-agnostic floating-point number. Thank you. -- Darren Duncan
Re: r29111 - docs/Perl6/Spec
On Wed, Nov 18, 2009 at 3:33 AM, Darren Duncan dar...@darrenduncan.net wrote: Acknowledging that 'FatRat' is current name for above 'Ratio' ... pugs-comm...@feather.perl6.nl wrote: -For applications that really need arbitrary precision denominators -as well as numerators, CRatio may be used, which is defined as CInt/Int. +For applications that really need arbitrary precision denominators as +well as numerators at the cost of performance, CRatio may be used, +which is stored as CInt/Int, that is, as arbitrary precision in +both parts. There is no literal form for a CRatio, so it must +be constructed using CRatio.new($nu,$de). In general, only math +operators with at least one CRatio argument will return another +CRatio, to prevent accidental promotion of reasonably fast CRat +values into arbitrarily slow CRatio values. Given the above, if one wants to construct a full-precision rational value in terms of 3 Int values analogous to a mantissa and radix and exponent, what is the best way to write it in Perl 6? For example, say I want the following expression to result in a FatRat because presumably that's the only type which will represent the result value exactly: 45207196 * 10 ** -37 How should that be spelled out in terms of 3 integers? And note that a decimal-specific answer isn't what I want, since I want something that would also work for this: 45207196 * 11 ** -37 Any thoughts? Basically where I'm coming from here is the idea that any rational can also be expressed as 3 integers like the above, not just the numerator/denominator pair; the 3 integers are advantages both for being efficient with common pathological cases such as very large or very small rationals with a small amount of precision, such as the above, as well as for exactly reflecting the concept of a radix-agnostic floating-point number. What's your objection to FatRat.new(45207196, 11 ** 37)? -- Solomon Foster: colo...@gmail.com HarmonyWare, Inc: http://www.harmonyware.com
Parrot 1.8.0 Zygodactyly Released!
On behalf of the Parrot team, I'm proud to announce Parrot 1.8.0 Zygodactyly. Parrot, http://parrot.org/, is a virtual machine aimed at running all dynamic languages. Parrot 1.8.0 is available on Parrot's FTP site ftp://ftp.parrot.org/pub/parrot/releases/devel/1.8.0/, or follow the download instructions at http://parrot.org/download. Parrot 1.8.0 News: - Functionality + The FileHandle PMC now exposes the exit code of child process that was run as pipe. + Experimental support for overriding VTABLE invoke in PIR objects was added. + The method 'type' was added to the PackfileAnnotations PMC. + The internals of the parrot calling conventions, PCC, were reworked. All call paths now use a CallSignature object for passing arguments and return values. + The new API-function 'Parrot_ext_call' was added for calling into C-land. + The fixed-size allocator was improved. + The files installed by 'make install-dev' are now covered by 'make install' as well. + The experimental ops 'fetch' and 'vivify' were added. + The -I option to the command 'parrot' now prepends items to the search path. + The Context struct was substituted with auto attributes (context_auto_attrs branch). + Use the osname determined in auto::arch in subsequent configuration steps (convert_OSNAME branch). + Eliminated dependence on Perl 5 '%Config' in auto::format (auto_format_no_Config branch). + MultiSub PMCs now stringify to the name of their first candidate, instead of the number of candidates. + The platform detection at the start of the configuration process was improved. + The 'lineof' method on CodeString objects now precomputes line number information to be more efficient on variable-width encoded strings. + P6object now supports .WHO and .WHERE methods on protoobjects. - Compilers + A shiny new self-hosting implementation of NQP has been added in ext/nqp-rx. - New NQP available as nqp-rx.pbc or parrot-nqp fakecutable. - NQP includes direct support for grammars and regexes, including protoregexes. - NQP has a new PAST-based regex engine (intended to replace PGE). - Regexes may contain code assertions, parameters, lexical declarations, and more. - Double-quoted strings now interpolate scalar variables and closures. - Subroutine declarations are now lexical by default. + PCT - PAST::Block now supports an 'nsentry' attribute. - PAST::Var allows 'contextual' scope. - Attribute bindings now return the bound value. - Platforms + Fixes for the port of Parrot to RTEMS were applied. Yay, first port to a real time OS! + On NetBSD, shared libs are now used. - Performance + Use the the fixed-sized allocator in the Context and the CallSignature PMC. + Many small speed improvements. - New deprecations + MT19937, the Mersenne twisted pseudorandom number generator, is now hosted on github and will be removed from the Parrot core. (eligible in 2.1) + The 'Parrot_call_*' functions for invoking a sub/method object from C are deprecated. They are replaced by 'Parrot_ext_call'. (eligible in 2.1) + All bitwise VTABLE functions are deprecated. (eligible in 2.1) + All bitwise ops will become dynops. (eligible in 2.1) - Realized deprecations + The slice VTABLE entry was removed. + The last traces of the 'malloc' garbage collector were removed. + Parrot_pcc_constants() was renamed to Parrot_pcc_get_constants(). + The deprecated functions from the Embedding/Extension interface were removed. + The library YAML/Parser/Syck.pir was removed. + The VTABLE function instantiate_str() was removed. + Building of parrot_nqp was removed. - Tests + The test coverage of the time-related ops was much improved. + New testing functions in Test::More: lives_ok() and dies_ok(). + The Perl 5 based test scripts t/op/bitwist.t, t/op/comp.t, t/op/inf_nan.t, t/op/literal.t, t/op/number.t, t/op/sprintf2.t, and t/op/00ff-dos.t were converted to PIR. + The test scripts t/op/annotate.t and t/op/time.t have begun to be translated from Perl 5 to PIR. + In some tests the dependency on %Config from Perl 5 was eliminated. - Documentation + The meaning of 'p' means in NCI function call signatures was clarified. - Tools + The stub for a new language, as created by mk_language_shell.pl, now relies on the PIR-based tools, which are replacing the Perl 5-based tools. + The library Configure.pir was added. + The library distutils.pir was added. - Miscellaneous + The mailing list parrot-users and a corresponding google group was created, http://groups.google.com/group/parrot-users. + Many bugfixes, code cleanups, and coding standard fixes. Many thanks to all our contributors for making this possible, and our sponsors for supporting this project. Our next scheduled release is December 15th 2009. Enjoy! -- Bernhard Schmalhofer
Re: r29111 - docs/Perl6/Spec
On Wed, Nov 18, 2009 at 12:33:35AM -0800, Darren Duncan wrote: Acknowledging that 'FatRat' is current name for above 'Ratio' ... pugs-comm...@feather.perl6.nl wrote: -For applications that really need arbitrary precision denominators -as well as numerators, CRatio may be used, which is defined as CInt/Int. +For applications that really need arbitrary precision denominators as +well as numerators at the cost of performance, CRatio may be used, +which is stored as CInt/Int, that is, as arbitrary precision in +both parts. There is no literal form for a CRatio, so it must +be constructed using CRatio.new($nu,$de). In general, only math +operators with at least one CRatio argument will return another +CRatio, to prevent accidental promotion of reasonably fast CRat +values into arbitrarily slow CRatio values. Given the above, if one wants to construct a full-precision rational value in terms of 3 Int values analogous to a mantissa and radix and exponent, what is the best way to write it in Perl 6? For example, say I want the following expression to result in a FatRat because presumably that's the only type which will represent the result value exactly: 45207196 * 10 ** -37 How should that be spelled out in terms of 3 integers? why 3? FatRat.new(45207196, 10**37); And note that a decimal-specific answer isn't what I want, since I want something that would also work for this: 45207196 * 11 ** -37 FatRat.new(45207196, 11**37); Any thoughts? Basically where I'm coming from here is the idea that any rational can also be expressed as 3 integers like the above, not just the numerator/denominator pair; the 3 integers are advantages both for being efficient with common pathological cases such as very large or very small rationals with a small amount of precision, such as the above, as well as for exactly reflecting the concept of a radix-agnostic floating-point number. I think that's an implementation detail. If you care much about it, you'll have to provide your Rat type. Cheers, Moritz
Re: r29121 - docs/Perl6/Spec
+Although most rational implementations normalize or reduce fractions +to their smallest representation immediately through a gcd algorithm, +Perl allows a rational datatype to do so lazily at need, such as +whenever the denominator would run out of precision, but avoid the +overhead otherwise. Hence, if you are adding a bunch of CRats that +represent, say, dollars and cents, the denominator may stay 100 the +entire way through. The C.nu and C.de methods will return these +unreduced values. You can use C$rat.=norm to normalize the fraction. +The C.perl method will produce a decimal number if the denominator is +a multiple of 10. Otherwise it will normalize and return a rational +literal of the form -47/3. Stringifying a rational always converts +to CNum and stringifies that, so the rational internal form is +somewhat hidden from the casual user, who would generally prefer +to see decimal notation. Wouldn't it be better to produce a decimal number if the denominator equals of 2**n * 5**m for n,m unsigned int? Before displaying the value should be decimal-normalized by multiplying numerator and denominator by 2**|n-m| or 5**|n-m| depending on sign(n-m). Otherwise adding Rats representing dollars and cents which are immediately normalized could produce flapping between rational literal form and decimal number form. Aside from that the specification should be: if the denominator equals 10**n, with n unsigned integer, .perl will produce a decimal number. Otherwise 1/30 would produce a decimal number like 0.033..., which was probably not intended. Regards, Ron
r29127 - docs/Perl6/Spec
Author: lwall Date: 2009-11-18 19:05:37 +0100 (Wed, 18 Nov 2009) New Revision: 29127 Modified: docs/Perl6/Spec/S02-bits.pod Log: [S02] correction from ron.koerner++ on s/multiple/power/ adopt 2's and 5's factoring as normative for both .Str and .perl of Rats Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-18 18:00:56 UTC (rev 29126) +++ docs/Perl6/Spec/S02-bits.pod2009-11-18 18:05:37 UTC (rev 29127) @@ -13,8 +13,8 @@ Created: 10 Aug 2004 -Last Modified: 17 Nov 2009 -Version: 189 +Last Modified: 18 Nov 2009 +Version: 190 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -709,12 +709,33 @@ entire way through. The C.nu and C.de methods will return these unreduced values. You can use C$rat.=norm to normalize the fraction. The C.perl method will produce a decimal number if the denominator is -a multiple of 10. Otherwise it will normalize and return a rational -literal of the form -47/3. Stringifying a rational always converts -to CNum and stringifies that, so the rational internal form is +a power of 10, or normalizable to a power of 10 (that is, having factors +of only 2 and 5). Otherwise it will normalize and return a rational +literal of the form C-47/3. Stringifying a rational does a similar +calculation, with the same result on decimal-normalizable fractions, +but where C.perl would produce the C-47/3 form, stringification instead +converts to CNum and stringifies that, so the rational internal form is somewhat hidden from the casual user, who would generally prefer -to see decimal notation. +to see pure decimal notation. +say 1/5;# 0.2 exactly (not via Num) +say 1/3;# 0.333 via Num + +say 2/6.perl +# 1/3 + +say 3.14159_26535_89793 +# 3.141592653589793 including last digit + +say 1.123 +# 1.123 + +say 5/5 +# 1 + +say 5/5.perl +# 1/1 + =item * Perl 6 should by default make standard IEEE floating point concepts
Rat.perl (was: [pugs-commits] r29121 - docs/Perl6/Spec)
pugs-comm...@feather.perl6.nl wrote: +The C.perl method will produce a decimal number if the denominator is +a multiple of 10. Otherwise it will normalize and return a rational +literal of the form -47/3. Did you mean a power of 10 instead? I can't see how it makes sense right now. This would be the .perl representation by current spec: 08:46 @moritz_ rakudo: say 357/12540 08:46 +p6eval rakudo 7347ec: 0.0284688995215311 instead of 08:44 @moritz_ rakudo: say (357/12540).perl 08:44 +p6eval rakudo 7347ec: 119/4180 At least I don't see the point of special-casing one trailing zero in the denominator. Cheers, Moritz -- Moritz Lenz http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/
r29128 - docs/Perl6/Spec
Author: lwall Date: 2009-11-18 19:51:35 +0100 (Wed, 18 Nov 2009) New Revision: 29128 Modified: docs/Perl6/Spec/S02-bits.pod Log: [S02] more Rat-to-Str fine-tuning wrt negative denominators Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-18 18:05:37 UTC (rev 29127) +++ docs/Perl6/Spec/S02-bits.pod2009-11-18 18:51:35 UTC (rev 29128) @@ -708,9 +708,10 @@ represent, say, dollars and cents, the denominator may stay 100 the entire way through. The C.nu and C.de methods will return these unreduced values. You can use C$rat.=norm to normalize the fraction. +(This also forces the sign on the denominator to be positive.) The C.perl method will produce a decimal number if the denominator is a power of 10, or normalizable to a power of 10 (that is, having factors -of only 2 and 5). Otherwise it will normalize and return a rational +of only 2 and 5 (and -1)). Otherwise it will normalize and return a rational literal of the form C-47/3. Stringifying a rational does a similar calculation, with the same result on decimal-normalizable fractions, but where C.perl would produce the C-47/3 form, stringification instead @@ -2864,7 +2865,12 @@ The purpose of this would be to facilitate compile-time analysis of multi-method dispatch, when the user prefers angle notation as the most readable way to represent a list of numbers, which it often is. +It also gives us a reasonable way of visually isolating any known +literal format as a single syntactic unit: +-1+2i.polar +(-1+2i).polar # same, but less clearly a literal + The degenerate case C is disallowed as a probable attempt to do IO in the style of Perl 5; that is now written Clines(). (C STDIN is also disallowed.) Empty lists are better written with
Re: r29121 - docs/Perl6/Spec
On Wed, Nov 18, 2009 at 03:08:59AM -0800, Ron wrote: : +Although most rational implementations normalize or reduce fractions : +to their smallest representation immediately through a gcd algorithm, : +Perl allows a rational datatype to do so lazily at need, such as : +whenever the denominator would run out of precision, but avoid the : +overhead otherwise. Hence, if you are adding a bunch of CRats that : +represent, say, dollars and cents, the denominator may stay 100 the : +entire way through. The C.nu and C.de methods will return these : +unreduced values. You can use C$rat.=norm to normalize the fraction. : +The C.perl method will produce a decimal number if the denominator is : +a multiple of 10. Otherwise it will normalize and return a rational : +literal of the form -47/3. Stringifying a rational always converts : +to CNum and stringifies that, so the rational internal form is : +somewhat hidden from the casual user, who would generally prefer : +to see decimal notation. : : Wouldn't it be better to produce a decimal number if the denominator : equals of 2**n * 5**m for n,m unsigned int? Before displaying the : value should be decimal-normalized by multiplying numerator and : denominator by 2**|n-m| or 5**|n-m| depending on sign(n-m). : Otherwise adding Rats representing dollars and cents which are : immediately normalized could produce flapping between rational literal : form and decimal number form. : Aside from that the specification should be: if the denominator equals : 10**n, with n unsigned integer, .perl will produce a decimal number. : Otherwise 1/30 would produce a decimal number like 0.033..., which : was probably not intended. Good catch; I thought power and typed multiple. I was hesitating to extend it to require factoring for the solution, but there's actually a fast way to factor for 2's and 5's. Just shift off all the 0 bits on the bottom to take out all the 2's, and then look up the remaining number to see if it's a power of 5. So I'm inclined to make normal stringification also produce an exact decimal by default and only failover to Num if .perl would produce the 1/3 form. In the absence of an explicit format, I think exactness should trump limiting the size of the resulting string arbitrarily. Larry
Re: r29111 - docs/Perl6/Spec
Moritz Lenz wrote: Given the above, if one wants to construct a full-precision rational value in terms of 3 Int values analogous to a mantissa and radix and exponent, what is the best way to write it in Perl 6? For example, say I want the following expression to result in a FatRat because presumably that's the only type which will represent the result value exactly: 45207196 * 10 ** -37 How should that be spelled out in terms of 3 integers? why 3? Because three attributes let you define them all as the same kind of int, instead of one having twice as many bits in it as the other: has int128 $whole, int128 $numerator, int128 $denominator vs. has int256 $numerator, int128 $denominator This matters when you reach the upper end of the low-level integer types, such that there is no longer an available integer type that has twice as many bits as the denominator type. But as you say, this is an implementation detail. The important thing for the Spec to note is that user expectations require Rational types to be able to handle a whole number part that's at least as large as the denominator part. Right now, the spec is addressing this in terms of implementation details: it assumes that a Rational will store exactly two numbers, representing the numerator and the denominator, and that the numerator must have twice as much storage space reserved for it as the denominator has. Why twice as much? So that no matter how large the denominator is, the numerator will be large enough to store a whole number part that's at least as large. The doubled bits isn't an end to itself, but merely a means to a more fundamental end. -- Jonathan Dataweaver Lang
Re: r29111 - docs/Perl6/Spec
Moritz Lenz wrote: On Wed, Nov 18, 2009 at 12:33:35AM -0800, Darren Duncan wrote: For example, say I want the following expression to result in a FatRat because presumably that's the only type which will represent the result value exactly: 45207196 * 10 ** -37 How should that be spelled out in terms of 3 integers? why 3? I think Jon Lang gave a good reply to that. I will also add, because that's conceptually what an IEEE float does, and technically an IEEE float is still exact precision but it is limited in what values it can represent so selecting an IEEE float value in the first place may involve rounding, but once you have, the 3-integer representation of a rational allows the float to be represented as a rational, tersely, and also radix agnostically if the 2 or 10 is explicit. And it works with just-as-minimal memory use when you convert from a 64-bit float like 8.125*2**-4000. FatRat.new(45207196, 10**37); And note that a decimal-specific answer isn't what I want, since I want something that would also work for this: 45207196 * 11 ** -37 FatRat.new(45207196, 11**37); Solomon Foster wrote: What's your objection to FatRat.new(45207196, 11 ** 37)? Well, for one thing, that's not the same value. I had a -37 as the exponent, designating a small non-integer rational value, whereas the FatRat example had flipped this around to 37, not the same value. Now I'm sure the format you showed looks great, but my concern is, does simply saying this: 11 ** -37 ... result in a FatRat and if not then how do I write 11^-37 in Perl 6 such that the resulting object retains the full precision of the value? -- Darren Duncan
r29129 - docs/Perl6/Spec
Author: lwall Date: 2009-11-19 05:34:29 +0100 (Thu, 19 Nov 2009) New Revision: 29129 Modified: docs/Perl6/Spec/S04-control.pod Log: [S04] as several folks have suggested, rename blorst to blast Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-11-18 18:51:35 UTC (rev 29128) +++ docs/Perl6/Spec/S04-control.pod 2009-11-19 04:34:29 UTC (rev 29129) @@ -1226,8 +1226,8 @@ our $temphandle = START maketemp(); In fact, most of these phasers will take either a block or a statement -(known as a Iblorst in the vernacular). -This can be particularly useful to expose a lexically scoped +(known as a Iblast in the vernacular). The statement form can be +particularly useful to expose a lexically scoped declaration to the surrounding context. Hence these declare the same variables with the same scope as the preceding example, but run the statements as a whole at the indicated time:
Re: r29129 - docs/Perl6/Spec
pugs-comm...@feather.perl6.nl wrote: Author: lwall Date: 2009-11-19 05:34:29 +0100 (Thu, 19 Nov 2009) New Revision: 29129 Modified: docs/Perl6/Spec/S04-control.pod Log: [S04] as several folks have suggested, rename blorst to blast Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-11-18 18:51:35 UTC (rev 29128) +++ docs/Perl6/Spec/S04-control.pod 2009-11-19 04:34:29 UTC (rev 29129) @@ -1226,8 +1226,8 @@ our $temphandle = START maketemp(); In fact, most of these phasers will take either a block or a statement -(known as a Iblorst in the vernacular). -This can be particularly useful to expose a lexically scoped +(known as a Iblast in the vernacular). The statement form can be +particularly useful to expose a lexically scoped declaration to the surrounding context. Hence these declare the same variables with the same scope as the preceding example, but run the statements as a whole at the indicated time: It was the best of times, it was the *blurst* of times! Stupid monkey!