Numerical and alphabetical suffixes: Difference between revisions
Content added Content deleted
(Add Factor example) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: implement scientific notation conversion at precision far beyond what the significant digits would suggest, tone down rhetoric) |
||
Line 458: | Line 458: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo|2018.09}} |
{{works with|Rakudo|2018.09}} |
||
Scientific notation, while supported in Perl 6, is limited to IEEE-754 64bit accuracy so there is some rounding on values using it. |
Scientific notation, while supported in Perl 6, is limited to IEEE-754 64bit accuracy so there is some rounding on values using it. Implements a custom "high precision" conversion routine. |
||
Unfortunately, this suffix routine is of limited use for practical everyday purposes. It focuses on handling excessively large and archaic units (googol, greatgross) and completely ignores or makes unusable (due to forcing case insensitivity) many common current ones: c(centi), m(milli), μ(micro). Ah well. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<lang perl6>my $googol = 10**100; |
|||
⚫ | |||
⚫ | |||
my %abr = |$/.map: { |
my %abr = |$/.map: { |
||
Line 489: | Line 492: | ||
my ($val, $unit, $fact) = $0, $1.Str.fc, $2.Str; |
my ($val, $unit, $fact) = $0, $1.Str.fc, $2.Str; |
||
$val.=subst(',', '', :g); |
$val.=subst(',', '', :g); |
||
if $val ~~ m:i/'e'/ { |
|||
my ($m,$e) = $val.split(/<[eE]>/); |
|||
$val = ($e < 0) |
|||
?? $m * FatRat.new(1,10**-$e) |
|||
!! $m * 10**$e; |
|||
} |
|||
my @suf = $unit; |
my @suf = $unit; |
||
unless %suffix{$unit}:exists { |
unless %suffix{$unit}:exists { |
||
Line 529: | Line 538: | ||
25.123Mi: 26,343,374.848 |
25.123Mi: 26,343,374.848 |
||
2.5123e-00002Gi: 26,975,615.844352 |
2.5123e-00002Gi: 26,975,615.844352 |
||
+.25123E-7Ei: 28,964,846,960. |
+.25123E-7Ei: 28,964,846,960.237816578048 |
||
-.25123e-34Vikki: -33,394. |
-.25123e-34Vikki: -33,394.19493810444147496234477542309678 |
||
2e-77gooGols: |
2e-77gooGols: 200,000,000,000,000,000,000,000 |
||
9!: 362,880 |
9!: 362,880 |
||
9!!: 945 |
9!!: 945 |