Numerical and alphabetical suffixes: Difference between revisions

→‎{{header|Perl 6}}: extend the precision some more
(→‎{{header|Factor}}: add EBNF solution)
(→‎{{header|Perl 6}}: extend the precision some more)
Line 552:
Note: I am blatantly and deliberately ignoring the task guidelines for formatting the output. It has no bearing on the core of the task. If you really, ''really'','' '''REALLY''' ''want to see badly formatted output, uncomment the last line.
 
<lang perl6>myuse $googol = 10**100Rat::Precise;
 
my $googol = 10**100;
«PAIRs 2 SCOres 20 DOZens 12 GRoss 144 GREATGRoss 1728 GOOGOLs $googol»
~~ m:g/ ((<.:Lu>+) <.:Ll>*) \s+ (\S+) /;
Line 564 ⟶ 566:
 
my %suffix = flat %abr,
(<K M G T P E Z Y X W V U>».fc Z=> (1000, * * 1000 … *)),
(<Ki Mi Gi Ti Pi Ei Zi Yi Xi Wi Vi Ui>».fc Z=> (1024, * * 1024 … *));
 
Line 571 ⟶ 573:
sub comma ($i is copy) {
my $s = $i < 0 ?? '-' !! '';
my ($whole, $frac) = $i.abssplit('.floor');
my $frac = $ifrac.abs - $wholedefined ?? '".' ~ $i.abs.split('.')[1]frac" !! '';
$s ~ $whole.abs.flip.comb(3).join(',').flip ~ $frac
}
 
Line 594 ⟶ 596:
$ret = [*] $ret, |@suf.map: { %suffix{$_} } if @suf[0];
$ret = [*] ($ret, * - $fact.chars …^ * < 2) if $fact.chars;
$ret.?precise ?? $ret.precise !! $ret
$ret
}
 
Line 610 ⟶ 612:
 
# Task required stupid layout
# say "\n In: $_\nOut : ", .words.map({comma .&units}).join(' ') for $test.lines;</lang>
{{out}}
<pre> 2greatGRo: 3,456
Line 627 ⟶ 629:
2.5123e-00002Gi: 26,975,615.844352
+.25123E-7Ei: 28,964,846,960.237816578048
-.25123e-34Vikki: -33,394.19493810444147496234477542309678194938104441474962344775423096782848
2e-77gooGols: 200,000,000,000,000,000,000,000
9!: 362,880
Line 638 ⟶ 640:
9!!!!!!!!: 9
9!!!!!!!!!: 9
.017K017k!!: 34,459,425</pre>
 
=={{header|REXX}}==
10,327

edits