Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -10,23 +10,23 @@ immutable huge = ["", ""] ~ ["m", "b", "tr", "quadr", "quint",
|
|||
"sext", "sept", "oct", "non", "dec"]
|
||||
.map!q{ a ~ "illion" }.array;
|
||||
|
||||
string spellBigInt(BigInt n) {
|
||||
static string nonZero(string c, BigInt n, string connect="") {
|
||||
return n == 0 ? "" : connect ~ c ~ n.spellBigInt;
|
||||
string spellBigInt(BigInt n) pure /*nothrow @safe*/ {
|
||||
static string nonZero(string c, BigInt n, string connect="") pure /*nothrow @safe*/ {
|
||||
return (n == 0) ? "" : (connect ~ c ~ n.spellBigInt);
|
||||
}
|
||||
|
||||
static string lastAnd(string num) {
|
||||
if (num.canFind(",")) {
|
||||
string pre = num.retro.find(",").retro[0 .. $ - 1];
|
||||
static string lastAnd(string num) pure /*nothrow*/ @safe {
|
||||
if (num.canFind(',')) {
|
||||
string pre = num.retro.find(',').retro[0 .. $ - 1];
|
||||
string last = num[pre.length + 1 .. $];
|
||||
if (!last.canFind(" and "))
|
||||
last = " and" ~ last;
|
||||
num = pre ~ "," ~ last;
|
||||
num = pre ~ ',' ~ last;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
static string big(in uint e, BigInt n) {
|
||||
static string big(in uint e, in BigInt n) pure /*nothrow @safe*/ {
|
||||
switch (e) {
|
||||
case 0: return n.spellBigInt;
|
||||
case 1: return n.spellBigInt ~ " thousand";
|
||||
|
|
@ -39,19 +39,19 @@ string spellBigInt(BigInt n) {
|
|||
} else if (n < 20) {
|
||||
return small[n.toInt];
|
||||
} else if (n < 100) {
|
||||
BigInt a = n / 10;
|
||||
BigInt b = n % 10;
|
||||
immutable BigInt a = n / 10;
|
||||
immutable BigInt b = n % 10;
|
||||
return tens[a.toInt] ~ nonZero("-", b);
|
||||
} else if (n < 1000) {
|
||||
BigInt a = n / 100;
|
||||
BigInt b = n % 100;
|
||||
} else if (n < 1_000) {
|
||||
immutable BigInt a = n / 100;
|
||||
immutable BigInt b = n % 100;
|
||||
return small[a.toInt] ~ " hundred" ~ nonZero(" ", b, " and");
|
||||
} else {
|
||||
string[] bigs;
|
||||
uint e = 0;
|
||||
while (n != 0) {
|
||||
BigInt r = n % 1000;
|
||||
n /= 1000;
|
||||
immutable BigInt r = n % 1_000;
|
||||
n /= 1_000;
|
||||
if (r != 0)
|
||||
bigs ~= big(e, r);
|
||||
e++;
|
||||
|
|
@ -63,7 +63,7 @@ string spellBigInt(BigInt n) {
|
|||
|
||||
version(number_names_main) {
|
||||
void main() {
|
||||
foreach (n; [0, -3, 5, -7, 11, -13, 17, -19, 23, -29])
|
||||
foreach (immutable n; [0, -3, 5, -7, 11, -13, 17, -19, 23, -29])
|
||||
writefln("%+4d -> %s", n, n.BigInt.spellBigInt);
|
||||
writeln;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue