view release on metacpan or search on metacpan
lib/Lingua/EO/Numbers.pm view on Meta::CPAN
b tr kvadr kvint sekst sept okt non dec undec duodec tredec
kvatuordec kvindec seksdec septendec oktodec novemdec vigint
>
);
Readonly my %WORDS => (
',' => 'komo',
'-' => 'negativa',
'+' => 'positiva',
inf => 'senfineco',
NaN => 'ne nombro',
);
# convert number to words
sub num2eo {
my ($number) = @_;
my @names;
return unless defined $number;
return $WORDS{NaN} if $number eq 'NaN';
if ($number =~ m/^ ( [-+] )? inf $/ix) {
# infinity
push @names, $1 ? $WORDS{$1} : (), $WORDS{inf};
}
elsif ($number =~ m/^ $RE{num}{real}{-radix=>'[,.]'}{-keep} $/x) {
my ($sign, $int, $frac) = ($2, $4, $6);
return if length $int > $MAX_INT_DIGITS;
lib/Lingua/EO/Numbers.pm view on Meta::CPAN
=head1 FUNCTIONS
The following functions are provided but are not exported by default.
=over 4
=item num2eo EXPR
If EXPR looks like a number, the text describing the number is returned. Both
integers and real numbers are supported, including negatives. Special values
such as "inf" and "NaN" are also supported.
=item num2eo_ordinal EXPR
If EXPR looks like an integer, the text describing the number in ordinal form
is returned. The behavior when passing a non-integer value is undefined.
=back
The returned string is UTF-8 encoded. If EXPR is a value that does not look
like a number or is not currently supported by this module, C<undef> is
lib/Lingua/EO/Numbers/EO.pod view on Meta::CPAN
=head1 FUNKCIOJ
La sekvanta funkcioj estas provizita sed ne estas eksportita implicite.
=over 4
=item num2eo EXPR
Se EXPR Åajnas kiel numero, la tekste priskribita numero estas liverita.
AmbaÅ entjeroj kaj reeloj estas subtenita, kio inkluzivas negativajn nombrojn.
Specialaj valoroj kiel "inf" kaj "NaN" estas ankaÅ subtenita.
=item num2eo_ordinal EXPR
Se EXPR Åajnas kiel entjero, la tekste priskribita orda numero estas liverita.
La konduto, kiam doni neentjera valoron, estas nedifinita.
=back
La liverita Äeno estas kodita de UTF-8. Se EXPR estas valoro, kio ne Åajnas
esti numero aÅ ne estas subtenita nun de Äi tiu modjulo, C<undef> estas
lib/Lingua/JBO/Numbers.pm view on Meta::CPAN
Readonly my $EMPTY_STR => q{};
Readonly my $ORDINAL_SUFFIX => q{moi};
Readonly my @NAMES => qw< no pa re ci vo mu xa ze bi so >;
Readonly my %WORDS => (
'.' => "pi",
',' => "ki'o",
'-' => "ni'u",
'+' => "ma'u",
inf => "ci'i",
NaN => "na namcu",
);
sub num2jbo {
my ($number) = @_;
my @names;
return unless defined $number;
return $WORDS{NaN} if $number eq 'NaN';
if ($number =~ m/^ ( [-+] )? inf $/ix) {
# infinity
push @names, $1 ? $WORDS{$1} : (), $WORDS{inf};
}
elsif ($number =~ m/^ $RE{num}{real}{-keep} $/x) {
my ($sign, $int, $frac) = ($2, $4, $6);
# sign and integer
push @names, (
lib/Lingua/JBO/Numbers.pm view on Meta::CPAN
=head1 FUNCTIONS
The following functions are provided but are not exported by default.
=over 4
=item num2jbo EXPR
If EXPR looks like a number, the text describing the number is returned. Both
integers and real numbers are supported, including negatives. Special values
such as "inf" and "NaN" are also supported.
=item num2jbo_ordinal EXPR
If EXPR looks like an integer, the text describing the number in ordinal form
is returned. The behavior when passing a non-integer value is undefined.
=back
If EXPR is a value that does not look like a number or is not currently
supported by this module, C<undef> is returned.
lib/Lingua/TLH/Numbers.pm view on Meta::CPAN
Readonly my @NAMES2 => $EMPTY_STR, qw< maH vatlh SaD netlh bIp 'uy' >;
# convert number to words
sub num2tlh {
my ($number) = @_;
my $digit_count = 0;
my @names;
return unless defined $number;
# NaN and inf not supported
return if $number eq 'NaN' || $number =~ m{^ [-+]? inf $}ix;
return if $number !~ m{^ $RE{num}{real}{-keep} $}x;
my ($sign, $int, $frac) = ($2, $4, $6);
# negatives not supported
return if $sign eq $MINUS;
return if length $int > $MAX_INT_DIGITS;
# integer
lib/Lingua/TLH/Numbers.pm view on Meta::CPAN
supported by this module, C<undef> is returned.
The C<:all> tag can be used to import all functions.
use Lingua::TLH::Numbers qw( :all );
=head1 TODO
=over 4
=item * support negatives, inf, and NaN
=item * support exponential notation
=item * option for the older ternary number system
=item * option for using "SanID" instead of "SaD" for "thousand"
=back
=head1 SEE ALSO
lib/Lingua/TokiPona/Numbers.pm view on Meta::CPAN
Readonly my $EMPTY_STR => q{};
Readonly my $SPACE => q{ };
Readonly my $MINUS => q{-};
Readonly my $ORDINAL_PARTICLE => q{nanpa};
Readonly my @NAMES => qw< ala wan tu mute ale >;
sub num2tokipona {
my ($number) = @_;
return unless looks_like_number $number;
return $NAMES[0] if $number eq 'NaN';
$number =~ s{^ ( [+-] ) }{}x;
my $sign = $1 || $EMPTY_STR;
return do {
if ($number eq 'inf') { $NAMES[4] }
elsif ($number == 0 ) { $NAMES[0] }
elsif ($number <= 1 ) { $NAMES[1] }
elsif ($number <= 2 ) { $NAMES[2] }
else { $NAMES[3] }
lib/Lingua/TokiPona/Numbers.pm view on Meta::CPAN
=head1 FUNCTIONS
The following functions are provided but are not exported by default.
=over 4
=item num2tokipona EXPR
If EXPR looks like a number, the text describing the number is returned. Both
integers and real numbers are supported, including negatives. Special values
such as "inf" and "NaN" are also supported.
=item num2tokipona_ordinal EXPR
If EXPR looks like an integer, the text describing the number in ordinal form
is returned. The behavior when passing a non-integer value is undefined.
=back
If EXPR is a value that does not look like a number or is not currently
supported by this module, C<undef> is returned.
t/conlang.t view on Meta::CPAN
binmode $builder->failure_output, ':utf8';
binmode $builder->todo_output, ':utf8';
use ok 'Lingua::Conlang::Numbers', qw( :all );
are_num2conlang(
[ eo => -9, 'negativa naÅ' ],
[ eo => 0, 'nul' ],
[ eo => 0.9, 'nul komo naÅ' ],
[ eo => 9, 'naÅ' ],
[ eo => 'NaN', 'ne nombro' ],
[ EO => 9, 'naÅ' ],
[ esperanto => 9, 'naÅ' ],
[ jbo => 9, 'so' ],
[ lojban => 9, 'so' ],
[ tokipona => 9, 'mute' ],
[ TokiPona => 9, 'mute' ],
[ toki_pona => 9, 'mute' ],
[ 'Toki Pona' => 9, 'mute' ],
);
[ '+9' => 'positiva naÅ' ],
[ '+9,0' => 'positiva naÅ komo nul' ],
[ '9,0' => 'naÅ komo nul' ],
[ '9,000' => 'naÅ komo nul nul nul' ],
[ '9.9' => 'naÅ komo naÅ' ],
# special values
[ 'inf' => 'senfineco' ],
[ '+inf' => 'positiva senfineco' ],
[ '-inf' => 'negativa senfineco' ],
[ 'NaN' => 'ne nombro' ],
# large numbers
[ 1000000, 'unu miliono' ],
[ 9000000, 'naÅ milionoj' ],
[ 9900000, 'naÅ milionoj naÅcent mil' ],
[ 1000000000, 'unu miliardo' ],
[ 1000000000000, 'unu biliono' ],
[ 999999999999999, 'naÅcent naÅdek naÅ bilionoj '
. 'naÅcent naÅdek naÅ miliardoj '
. 'naÅcent naÅdek naÅ milionoj '
[ '9.' => "so" ],
[ '+9' => "ma'uso" ],
[ '+9.0' => "ma'usopino" ],
[ '9.0' => "sopino" ],
[ '9.000' => "sopinonono" ],
# special values
[ 'inf' => "ci'i" ],
[ '+inf' => "ma'uci'i" ],
[ '-inf' => "ni'uci'i" ],
[ 'NaN' => "na namcu" ],
);
# ordinals
are_num2jbo_ordinal(
[ '+9', "ma'usomoi" ],
[ -9, "ni'usomoi" ],
[ 0, "nomoi" ],
[ 9, "somoi" ],
[ 10, "panomoi" ],
[ 90, "sonomoi" ],
TODO: {
our $TODO = 'negative numbers not implemented';
for my $test (-9, -9.0, -0.9, '-9', '-9.0') {
ok num2tlh($test), "$test returns value";
}
}
TODO: {
our $TODO = 'special values inf and NaN not implemented';
for my $test (qw< inf +inf -inf NaN >) {
ok num2tlh($test), "$test returns value";
}
}
TODO: {
our $TODO = 'exponential notation in strings not implemented';
for my $test (qw< 5e5 5E5 5.5e5 5e-5 -5e5 -5e-5 >) {
ok num2tlh($test), "$test returns value";
}
t/tokipona.t view on Meta::CPAN
[ '.1' => 'wan' ],
[ '1' => 'wan' ],
[ '1.' => 'wan' ],
[ '+1' => 'wan' ],
[ '+1.0' => 'wan' ],
# special values
[ 'inf' => 'ale' ],
[ '+inf' => 'ale' ],
[ '-inf' => 'ale ala' ],
[ 'NaN' => 'ala' ],
);
# ordinals
are_num2tokipona_ordinal(
[ 0, 'nanpa ala' ],
[ 1, 'nanpa wan' ],
[ 2, 'nanpa tu' ],
[ 3, 'nanpa mute' ],
[ 4, 'nanpa mute' ],
[ 10, 'nanpa mute' ],