| 1 | # -*- mode: perl; -*- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Math::BigInt::Named::German; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.006001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Math::BigInt::Named; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | our @ISA = qw< Math::BigInt::Named >; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub name | ||||||||||||||||||||||||||||
| 15 | 51 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | # output the name of the number | ||||||||||||||||||||||||||||
| 17 | 51 | my ($x) = shift; | |||||||||||||||||||||||||||
| 18 | 51 | ▶ | $x = Math::BigInt->new($x) unless ref($x); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 51 | my $self = ref($x); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 51 | ▶ | return '' if $x->is_nan(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 51 | my $index = 0; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 51 | my $ret = ''; | |||||||||||||||||||||||||||
| 27 | 51 | my $y = $x->copy(); my $rem; | |||||||||||||||||||||||||||
| 28 | 51 | ▶ | if ($y->sign() eq '-') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 1 | $ret = 'minus '; | |||||||||||||||||||||||||||
| 31 | 1 | $y->babs(); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 51 | ▶ | if ($y < 1000) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 44 | return $ret . $self->_triple($y,1,0); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 7 | ▶ | while (!$y->is_zero()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||
| 39 | 14 | ($y,$rem) = $y->bdiv(1000); | |||||||||||||||||||||||||||
| 40 | 14 | $ret = $self->_triple($rem,0,$index) | |||||||||||||||||||||||||||
| 41 | .' ' . $self->_triple_name($index,$rem) . ' ' . $ret; | ||||||||||||||||||||||||||||
| 42 | 14 | $index++; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 7 | $ret =~ s/\s+$//; # trailing spaces | |||||||||||||||||||||||||||
| 45 | 7 | $ret; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | my $SMALL = [ qw/ | |||||||||||||||||||||||||||
| 49 | null | ||||||||||||||||||||||||||||
| 50 | eins | ||||||||||||||||||||||||||||
| 51 | zwei | ||||||||||||||||||||||||||||
| 52 | drei | ||||||||||||||||||||||||||||
| 53 | vier | ||||||||||||||||||||||||||||
| 54 | fuenf | ||||||||||||||||||||||||||||
| 55 | sechs | ||||||||||||||||||||||||||||
| 56 | sieben | ||||||||||||||||||||||||||||
| 57 | acht | ||||||||||||||||||||||||||||
| 58 | neun | ||||||||||||||||||||||||||||
| 59 | zehn | ||||||||||||||||||||||||||||
| 60 | oelf | ||||||||||||||||||||||||||||
| 61 | zwoelf | ||||||||||||||||||||||||||||
| 62 | dreizehn | ||||||||||||||||||||||||||||
| 63 | vierzehn | ||||||||||||||||||||||||||||
| 64 | fuenfzehn | ||||||||||||||||||||||||||||
| 65 | sechzehn | ||||||||||||||||||||||||||||
| 66 | siebzehn | ||||||||||||||||||||||||||||
| 67 | achtzehn | ||||||||||||||||||||||||||||
| 68 | neunzehn | ||||||||||||||||||||||||||||
| 69 | / ]; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 3 | my $ZEHN = [ qw / | |||||||||||||||||||||||||||
| 72 | zehn | ||||||||||||||||||||||||||||
| 73 | zwanzig | ||||||||||||||||||||||||||||
| 74 | dreissig | ||||||||||||||||||||||||||||
| 75 | vierzig | ||||||||||||||||||||||||||||
| 76 | fuenfzig | ||||||||||||||||||||||||||||
| 77 | sechzig | ||||||||||||||||||||||||||||
| 78 | siebzig | ||||||||||||||||||||||||||||
| 79 | achtzig | ||||||||||||||||||||||||||||
| 80 | neunzig | ||||||||||||||||||||||||||||
| 81 | / ]; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 3 | my $HUNDERT = [ qw / | |||||||||||||||||||||||||||
| 84 | ein | ||||||||||||||||||||||||||||
| 85 | zwei | ||||||||||||||||||||||||||||
| 86 | drei | ||||||||||||||||||||||||||||
| 87 | vier | ||||||||||||||||||||||||||||
| 88 | fuenf | ||||||||||||||||||||||||||||
| 89 | sechs | ||||||||||||||||||||||||||||
| 90 | sieben | ||||||||||||||||||||||||||||
| 91 | acht | ||||||||||||||||||||||||||||
| 92 | neun | ||||||||||||||||||||||||||||
| 93 | / ]; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | my $TRIPLE = [ qw / | |||||||||||||||||||||||||||
| 96 | mi | ||||||||||||||||||||||||||||
| 97 | bi | ||||||||||||||||||||||||||||
| 98 | tri | ||||||||||||||||||||||||||||
| 99 | quadri | ||||||||||||||||||||||||||||
| 100 | penti | ||||||||||||||||||||||||||||
| 101 | hexi | ||||||||||||||||||||||||||||
| 102 | septi | ||||||||||||||||||||||||||||
| 103 | octi | ||||||||||||||||||||||||||||
| 104 | / ]; | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | sub _triple_name | ||||||||||||||||||||||||||||
| 107 | 49 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_triple_name: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 108 | 49 | my ($self,$index,$number) = @_; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 49 | ▶ | return '' if $index == 0 || $number->is_zero(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$index == 0 or $number->is_zero
MC/DC100%2/2
$index == 0 or $number->is_zero
$index == 0
$number->is_zero
Truth table100%3/3
A or B
A= $index == 0B= $number->is_zero
| |||||||||||||||||||||||||||||
| 111 | 40 | ▶ | return 'tausend' if $index == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 32 | my $postfix = 'llion'; my $plural = 'en'; | |||||||||||||||||||||||||||
| 114 | 32 | ▶ | if ($index & 1 == 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | 16 | $postfix = 'lliarde'; $plural = 'n'; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 32 | ▶ | $postfix .= $plural unless $number->is_one(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 32 | $index -= 2; | |||||||||||||||||||||||||||
| 120 | 32 | $TRIPLE->[$index >> 1] . $postfix; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | sub _triple | ||||||||||||||||||||||||||||
| 124 | 58 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_triple: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||
| 125 | # return name of a triple (aka >= 0, and <= 1000) | ||||||||||||||||||||||||||||
| 126 | # input: number >= 0, < 1000) | ||||||||||||||||||||||||||||
| 127 | # only true if triple is the only triple ever ($nr < 1000) | ||||||||||||||||||||||||||||
| 128 | # index 0 for last triple, 1 for tausend, 2 for million etc | ||||||||||||||||||||||||||||
| 129 | 58 | my ($self,$number,$only,$index) = @_; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # eins, ein hundert, ein tausend, eine million | ||||||||||||||||||||||||||||
| 132 | # zwei, zwei hundert, zwei tausend, zwei million | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 58 | my $eins = 'ein'; | |||||||||||||||||||||||||||
| 135 | 58 | ▶ | $eins = 'eins' if $index == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 58 | ▶ | $eins = 'eine' if $index > 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 58 | ▶ | return '' if $number->is_zero() && !$only; # 0 => null, but only for one | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$number->is_zero and not $only
MC/DC100%2/2
$number->is_zero and not $only
$number->is_zero
not $only
Truth table100%3/3
A and not(B)
A= $number->is_zeroB= not $only
| |||||||||||||||||||||||||||||
| 139 | 57 | ▶ | return $eins if $number->is_one(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 47 | ▶ | return $SMALL->[$number] if $number < scalar @$SMALL; # known name | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 27 | my $hundert = $number / 100; | |||||||||||||||||||||||||||
| 143 | 27 | my $rem = $number % 100; | |||||||||||||||||||||||||||
| 144 | 27 | my $rc = ''; | |||||||||||||||||||||||||||
| 145 | 27 | ▶ | $rc = "$HUNDERT->[$hundert-1]hundert" if !$hundert->is_zero(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 27 | ▶ | my $concat = ''; $concat = 'und' if $rc ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 27 | ▶ | return $rc if $rem->is_zero(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 18 | ▶ | return $rc . $concat . $SMALL->[$rem] if $rem < scalar @$SMALL; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 15 | my $zehn; ($zehn,$rem) = $rem->bdiv(10); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 15 | ▶ | $rc .= $concat . $HUNDERT->[$rem-1] if !$rem->is_zero(); # 31, 32.. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 15 | ▶ | $concat = ''; $concat = 'und' if $rc ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 15 | ▶ | $rc .= $concat . $ZEHN->[$zehn-1] if !$zehn->is_zero(); # 1,2,3.. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 15 | $rc; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 3 | 1; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||