1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
//! Port of `lang_YO.py` (Yoruba).
//!
//! Shape: **self-contained**. `Num2Word_YO` subclasses `Num2Word_Base` but
//! defines no `high_numwords`/`mid_numwords`/`low_numwords`, so Python's
//! `Num2Word_Base.__init__` never enters the `if any(hasattr(...))` branch:
//! `self.cards` is never built and `self.MAXVAL` is never set. `to_cardinal`
//! is overridden outright and drives a recursive `_int_to_word`. Accordingly
//! `cards`/`maxval`/`merge` stay at their trait defaults here, and there is
//! **no overflow check** — no input can raise `OverflowError`, because
//! `_int_to_word` has a `str(number)` fallback instead of a ceiling (bug 1).
//!
//! `setup()` supplies `negword = "minus "` (note the trailing space) and
//! `pointword = "point"`. Every in-scope entry point is overridden by
//! `Num2Word_YO`, so nothing is inherited from `Num2Word_Base` except the
//! attributes above:
//! * `to_cardinal` — overridden (see below)
//! * `to_ordinal` — overridden: `to_cardinal(n) + "-kẹta"`
//! * `to_ordinal_num` — overridden: `str(n) + "."`
//! * `to_year` — overridden: `to_cardinal(val)`, ignoring `longval`
//!
//! No cross-call mutable state: `Num2Word_YO` defines no `str_to_number` and
//! stashes no flags between methods, so the stateless Rust path is faithful.
//!
//! # Faithfully reproduced Python bugs / oddities
//!
//! This is a port, not a rewrite. All of the following look wrong but are
//! exactly what Python emits, verified against the frozen corpus:
//!
//! 1. **`_int_to_word` gives up at 10^9 and returns the bare digits.** The
//! final `else` is `return str(number)`, so `to_cardinal(10**9)` ==
//! `"1000000000"` — digits, not words — and `to_ordinal(10**9)` ==
//! `"1000000000-kẹta"`. There is no `million`-and-up table (`setup` stops
//! at `self.million`), and no exception is ever raised. The fallback keeps
//! full precision for arbitrarily large input, hence the `BigInt`
//! `to_string()` in [`LangYo::int_to_word`] — the corpus exercises 10^21.
//! Because `to_cardinal` strips the sign *before* recursing, a large
//! negative renders as `"minus 1000000000"`.
//!
//! 2. **Hundreds are formed as `ones[h] + " " + hundred`,** so 100 is
//! `"ọkan ọgọrun"` ("one hundred") rather than a bare `"ọgọrun"`. Kept.
//!
//! 3. **`to_ordinal` appends a fixed `"-kẹta"` to the cardinal** — `kẹta` is
//! the Yoruba ordinal for *third*, so every ordinal literally reads
//! "<n>-third": `to_ordinal(1)` == `"ọkan-kẹta"`, `to_ordinal(0)` ==
//! `"zero-kẹta"`. It is a fixed suffix, not agreement, and unlike most
//! modules it neither rejects 0 nor rejects negatives:
//! `to_ordinal(-1)` == `"minus ọkan-kẹta"`. No exception path exists.
//!
//! 4. **`_int_to_word(0)` is written `self.ones[0] if self.ones[0] else "zero"`.**
//! `ones[0]` is `""` — falsy — so the conditional always takes the `else`
//! and returns the English `"zero"`. The `ones[0]` arm is unreachable dead
//! code; modelled here as the constant [`ZERO`].
//!
//! 5. **The `number < 0` arm of `_int_to_word` is unreachable** from every
//! in-scope entry point: `to_cardinal` strips the leading `"-"` from the
//! *string* and prepends `negword` itself, so `_int_to_word` only ever
//! sees a non-negative value. It is reproduced anyway (see
//! [`LangYo::int_to_word`]) because it is part of the function's
//! semantics, and it would double the negword if it ever were reached.
//!
//! # Currency
//!
//! `Num2Word_YO` overrides `to_currency` **wholesale** — it never reaches
//! `Num2Word_Base.to_currency`, so none of `parse_currency_parts`,
//! `pluralize`, `_cents_verbose`, `_cents_terse` or `CURRENCY_PRECISION`
//! participate. It re-derives the split itself from `str(val)`. See
//! [`LangYo::to_currency`].
//!
//! `to_cheque` is *not* overridden, so it comes from `Num2Word_Base` via the
//! trait default (`currency::default_to_cheque`), which needs only
//! [`Lang::currency_forms`] + [`Lang::lang_name`] + the default
//! `money_verbose` (= `to_cardinal`) from this file.
//!
//! `CURRENCY_FORMS` is defined directly on `Num2Word_YO` (NGN, USD, EUR) and
//! is **not** the shared `Num2Word_EUR` dict, so the `lang_EN` mutation trap
//! described in `PORTING_CURRENCY.md` does not apply here — Yoruba never sees
//! EN's ~24 extra codes. `CURRENCY_ADJECTIVES` and `CURRENCY_PRECISION` are
//! inherited from `Num2Word_Base` and are both `{}`, so the trait defaults
//! (`None` / `100`) are already correct and are not overridden. Verified
//! against the live interpreter.
//!
//! # Faithfully reproduced Python bugs / oddities — currency
//!
//! 6. **An unknown currency code silently falls back to NGN** rather than
//! raising. `to_currency` looks the code up with
//! `CURRENCY_FORMS.get(currency, list(CURRENCY_FORMS.values())[0])`, and
//! `values()[0]` is NGN because it is first in the dict literal. So
//! `to_currency(1, currency="GBP")` == `"ọkan náírà"` — pounds rendered as
//! naira. The corpus pins this for GBP/JPY/KWD/BHD/INR/CNY/CHF.
//! `to_cheque` does **not** share the fallback: it indexes
//! `CURRENCY_FORMS[currency]` and raises `NotImplementedError`. Hence
//! [`Lang::currency_forms`] here reports the honest `None` for a missing
//! code (so cheque raises) and the NGN fallback lives *only* inside
//! [`LangYo::to_currency`], exactly mirroring the two Python call sites.
//!
//! 7. **Cents are truncated to 2 digits, never rounded.** The subunit comes
//! from `int(parts[1][:2].ljust(2, "0"))` — a *string* slice of `str(val)`.
//! So `2.675` -> 67 cents (not 68; there is no ROUND_HALF_UP anywhere),
//! `1.005` -> 0 cents, and `0.0001` -> `"zero euros"`. Conversely `1.5`
//! -> `"5"` -> ljust -> `"50"` -> 50 cents, i.e. the slice is positional,
//! not numeric.
//!
//! 8. **`CURRENCY_PRECISION` is ignored entirely.** JPY (0-decimal) and
//! KWD/BHD (3-decimal) are not in `CURRENCY_FORMS` anyway, so they take
//! the NGN fallback *and* the hardcoded 2-digit cent slice: `to_currency
//! (12.34, currency="JPY")` == `"mẹwa méjì náírà ọgbọn mẹrin kóbò"` —
//! yen with naira subunits. Both corpus-pinned.
//!
//! 9. **`adjective` is accepted and then ignored.** `Num2Word_YO.to_currency`
//! never reads it (and `CURRENCY_ADJECTIVES` is empty regardless), so
//! `adjective=True` changes nothing.
//!
//! 10. **`cents=False` drops the subunit clause entirely.** Python's guard is
//! `if cents and right:`. In `Num2Word_Base` `cents=False` means "render
//! the subunit as digits" (`_cents_terse`); here it means "omit". So
//! `to_currency(12.34, cents=False)` == `"mẹwa méjì euros"`.
//!
//! 11. **A float whose `repr` is scientific crashes or silently mis-reads.**
//! Because the split is done on `str(val)` rather than on the number,
//! `str(1e16)` == `"1e+16"` reaches `int()` and raises `ValueError`, while
//! `str(1.25e16)` == `"1.25e+16"` splits into `"1"` / `"25e+16"`, whose
//! first two chars are `"25"` — so `1.25e16` renders as
//! `"ọkan euro ogún marun cents"` (one euro, twenty-five cents). See
//! [`py_str`] for how this is reproduced.
//!
//! 12. **The `separator` default is `" "`, not Base's `","`.** Python's
//! signature is `to_currency(self, val, currency="NGN", cents=True,
//! separator=" ", adjective=False)`, so the corpus — which never passes
//! `separator=` — records `"mẹwa méjì euros ọgbọn mẹrin cents"` rather than
//! `"...euros,ọgbọn..."`. Not a bug so much as a divergence from Base that
//! is easy to lose: [`Lang::default_separator`] carries it, and
//! `to_currency` receives `None` when the caller omitted the kwarg.
//!
//! # Float/Decimal cardinal
//!
//! `Num2Word_YO.to_cardinal` handles non-integers inline: it never calls
//! `Num2Word_Base.to_cardinal_float`, never runs `float2tuple`, and does **no
//! arithmetic at all** — the whole algorithm is string surgery on
//! `str(number)`:
//!
//! ```python
//! n = str(number).strip()
//! if n.startswith("-"): n = n[1:]; ret = self.negword
//! if "." in n:
//! left, right = n.split(".", 1)
//! ret += self._int_to_word(int(left)) + " " + self.pointword + " "
//! for digit in right:
//! ret += self._int_to_word(int(digit)) + " "
//! return ret.strip()
//! ```
//!
//! So [`LangYo::to_cardinal_float`] reconstructs the text Python saw —
//! `repr(float)` via the same [`py_str`] the currency port already uses, and
//! `str(Decimal)` via [`decimal_str_abs`] — then runs the string algorithm.
//! The base-path traps (banker's rounding, the `< 0.01` float2tuple rescue)
//! do not apply here: for Yoruba the decimal *string* is the spec, so `2.675`
//! reads its repr digits verbatim (`"méjì point mẹfa meje marun"`) and `1.005`
//! keeps its leading zeros (`"ọkan point zero zero marun"`).
//!
//! # Faithfully reproduced Python bugs / oddities — float cardinal
//!
//! 13. **A scientific-notation repr raises ValueError**, same family as
//! bug 11: `str(1e-05)` == `"1e-05"` has no `"."`, so the whole literal
//! hits `int()` — `invalid literal for int() with base 10: '1e-05'` —
//! while `str(1.5e-05)` == `"1.5e-05"` *does* split, and the digit loop
//! dies on the `'e'` (`... base 10: 'e'`). Decimals keep their own
//! spelling: `Decimal("1E-7")` fails on `'1E-7'`, `Decimal("1.5E-7")` on
//! `'E'` (capital, unpadded — Decimal's `__str__`, not float `repr`).
//! All four messages verified against the live interpreter.
//!
//! 14. **The `precision=` kwarg is a no-op.** The dispatcher sets
//! `converter.precision` (the attribute exists, inherited from Base), but
//! `Num2Word_YO.to_cardinal` never reads it — the digit count comes from
//! the text. Base-path languages honour it; Yoruba ignores it, so
//! `precision_override` is deliberately discarded. Verified live:
//! `to_cardinal(3.14)` with `precision=5` is still
//! `"mẹta point ọkan mẹrin"`.
//!
//! 15. **A whole float keeps its fractional clause**: `repr(1.0)` is `"1.0"`,
//! so Python renders `"ọkan point zero"`, never bare `"ọkan"` (corpus rows
//! `0.0`/`1.0` pin this). The dispatcher routes whole floats to the Python
//! converter, so the Rust hook only ever *receives* non-whole values — but
//! the reconstruction appends `repr`'s `".0"` anyway, so both sides agree
//! even on a direct call.
//!
//! 16. **Float noise is spelled out digit by digit.** There is no rounding
//! rescue anywhere, so `0.30000000000000004` becomes `"zero point mẹta"`
//! followed by fifteen `"zero"`s and a `"mẹrin"` — 17 fraction words,
//! exactly the repr digits. Similarly the `>= 10**9` fallback (bug 1)
//! applies to the integer part: `Decimal("98746251323029.99")` is
//! `"98746251323029 point mẹsan mẹsan"` (corpus-pinned).
//!
//! # Error variants
//!
//! The four integer modes raise nothing: there is no overflow ceiling
//! (bug 1), no ordinal guard (bug 3), and no dict/list lookup that can miss —
//! every index into `ones`/`tens` is derived from `n // 10 % 10` and is in
//! range by construction. All four modes are total over the integers.
//!
//! The currency and float surfaces add exactly two:
//!
//! * `N2WError::Value` — `to_currency` or the float cardinal on a value whose
//! `str()` is scientific notation, where Python's `int()` chokes on the
//! literal (bugs 11 and 13).
//! * `N2WError::NotImplemented` — `to_cheque` with a code outside
//! {NGN, USD, EUR}, raised by the inherited `Num2Word_Base.to_cheque`.
//! `to_currency` never raises this (bug 6).
use crate;
use crate;
use crateFloatValue;
use crate;
use BigDecimal;
use BigInt;
use ;
use HashMap;
use FromStr;
/// `_int_to_word(0)`. Python writes `self.ones[0] if self.ones[0] else "zero"`,
/// and `ones[0]` is `""`, so this constant is the only reachable result.
const ZERO: &str = "zero";
/// `setup()`: `self.negword = "minus "` — the trailing space is load-bearing.
/// `to_cardinal` concatenates it directly (`ret + word`) rather than joining,
/// then `.strip()`s the result.
const NEGWORD: &str = "minus ";
/// `self.ones`, indices 0..=9. Index 0 is `""` (see [`ZERO`] and bug 4); it is
/// never selected by the `number < 10` arm, which is guarded by `number != 0`.
const ONES: = ;
/// `self.tens`, indices 0..=9, keyed by the tens digit. Index 0 is `""` and is
/// unreachable: the `number < 100` arm requires `number >= 10`, so
/// `number // 10 >= 1`. Note index 1 (`"mẹwa"`, ten) is reused for the teens,
/// so 11 is `"mẹwa ọkan"` — literally "ten one", with no dedicated teen words.
const TENS: = ;
/// `self.hundred`.
const HUNDRED: &str = "ọgọrun";
/// `self.thousand`.
const THOUSAND: &str = "ẹgbẹrun";
/// `self.million`.
const MILLION: &str = "miliọnu";
/// `to_ordinal`'s fixed suffix — see bug 3.
const ORDINAL_SUFFIX: &str = "-kẹta";
/// The ceiling of `_int_to_word`'s word-forming branches. At or above this,
/// Python returns `str(number)` verbatim (bug 1).
const FALLBACK_THRESHOLD: u64 = 1_000_000_000;
/// The code `list(CURRENCY_FORMS.values())[0]` resolves to — the first key in
/// `Num2Word_YO`'s dict literal, which Python dicts preserve in insertion
/// order. `to_currency` uses it as the fallback for an unknown code (bug 6).
const FALLBACK_CURRENCY: &str = "NGN";
/// `Num2Word_YO.CURRENCY_FORMS`, in the dict literal's insertion order.
///
/// Defined directly on `Num2Word_YO`, so — unlike the 16 classes that read the
/// shared `Num2Word_EUR` dict — this table is **not** touched by
/// `Num2Word_EN.__init__`'s in-place mutation, and Yoruba never sees EN's ~24
/// extra codes. Verified against the live interpreter: `CURRENCY_FORMS.keys()`
/// is exactly `['NGN', 'USD', 'EUR']`.
///
/// The order is load-bearing: `to_currency`'s fallback is
/// `list(CURRENCY_FORMS.values())[0]`, and Python dicts preserve insertion
/// order, so NGN — declared first — is what an unknown code resolves to
/// (bug 6). [`FALLBACK_CURRENCY`] pins that as a named lookup rather than
/// relying on `HashMap` iteration order, which is arbitrary.
///
/// Every entry carries exactly two forms, matching the Python tuples, so the
/// `cr1[1]`/`cr2[1]` indexing below can never raise IndexError. NGN's two unit
/// forms are deliberately identical (`("náírà", "náírà")`) — Yoruba does not
/// inflect the noun for number here — which is why "ọkan náírà" and "méjì
/// náírà" share a word where USD alternates dollar/dollars.
/// Python's `int(s)` for a `str`, reproducing its `ValueError`.
///
/// `Num2Word_YO.to_currency` feeds `int()` slices of `str(val)`, which for a
/// scientific-notation `repr` are not numeric at all (bug 11). The exception
/// type is the observable part — `bench/diff_test.py` compares
/// `type(e).__name__` — and `N2WError::Value` is what the generated binding
/// maps to `PyValueError`.
///
/// Python additionally accepts `_` separators and non-ASCII decimal digits.
/// Neither can occur here: every string handed to this function is produced by
/// [`py_str`] out of a `BigInt`'s ASCII digits, so the narrower grammar is
/// exact for all reachable input.
/// Reconstruct Python's `str(value)` for the value the shim stringified.
///
/// # Why this exists
///
/// `Num2Word_YO.to_currency` does not do arithmetic on the number — it does
/// `str(val).split(".")` and slices the *text*. Every one of its quirks (the
/// 2-char truncation of bug 7, the `ValueError` and the 25-cents misread of
/// bug 11) is a property of that text. So the faithful port reconstructs the
/// text and then runs Python's algorithm on it, rather than re-deriving the
/// split numerically and hoping the edge cases agree.
///
/// # Why it is not a `repr(float)` reimplementation
///
/// `currency.rs` deliberately keeps shortest-round-trip float formatting on
/// the Python side, and this does not bring it back. The *digits* arrive
/// already chosen: the shim sent `str(value)`, and `bigdecimal`'s parser
/// stores them verbatim as `(int_val, scale)` without normalising, so
/// `as_bigint_and_exponent()` hands back exactly the digits `repr` produced.
/// All that is recovered here is the **layout** — where `repr` put the point,
/// and whether it chose exponential form — which is a plain range check on the
/// decimal exponent, not a formatting algorithm.
///
/// `decpt` is the decimal point's position relative to the digit string
/// (`value == 0.<digits> * 10^decpt`). CPython's `float_repr` emits fixed
/// notation for `-4 < decpt <= 16` and exponential outside it, which is why
/// `str(1e15)` is `"1000000000000000.0"` but `str(1e16)` is `"1e+16"`, and
/// `str(1e-4)` is `"0.0001"` but `str(1e-5)` is `"1e-05"`. Verified against
/// the interpreter across that whole boundary.
///
/// # Limits
///
/// `digits` must be the **absolute** value: Python evaluates `val = abs(val)`
/// before `str(val)`, so a negative never reaches the text. (`-0.0` is the one
/// exception — `-0.0 < 0` is `False`, so Python stringifies `"-0.0"` and
/// `int("-0")` yields `0`. `bigdecimal` has no signed zero, so this returns
/// `"0.0"` and `int("0")` yields the same `0`. Indistinguishable in output.)
///
/// The layout rule is `repr(float)`'s, and it is **exact for every `float` and
/// `int`** — the two types the corpus exercises. Fuzzed against the live
/// interpreter over ~125k `to_currency`/`to_cheque` calls, including a sweep of
/// `{1.0, 1.25, 9.99, 5.0, 1.5} x 10^{-12..23}` that straddles both
/// notation boundaries in both directions: zero mismatches.
///
/// `decimal.Decimal` — which `num2words()` also accepts (`__init__.py` admits
/// `(int, float, Decimal)` and sends `str(number)`) — formats itself by
/// *different* rules, and there the reconstruction can diverge. `str(Decimal)`
/// preserves the literal's own notation; `repr(float)` imposes the decpt rule
/// above. Three known divergences, all verified against the interpreter:
///
/// | input | Python | this port |
/// |---|---|---|
/// | `Decimal("0.00001")` | `"zero euros"` | ValueError |
/// | `Decimal("1e-5")` | `"zero euros"` | ValueError |
/// | `Decimal("1E+2")` | ValueError | `"ọkan ọgọrun euros"` |
///
/// The first two are **not fixable here, even in principle**:
/// `Decimal("0.00001")` and the float `1e-05` both parse to exactly
/// `(digits: 1, scale: 5)`, yet Python renders one `"zero euros"` and raises on
/// the other. The distinguishing information is the *spelling*, which
/// `CurrencyValue::parse` consumes before this file is reached. The fix belongs
/// at the boundary — `CurrencyValue::Decimal` would have to carry the original
/// `str(val)` alongside the parsed number, the same way `has_decimal` already
/// crosses because it too cannot be recovered from the value. That is a
/// `currency.rs` + binding change, out of scope for a single-language port.
///
/// `Decimal("1E+2")` *is* separable (a float repr can never yield `scale < 0`
/// with `decpt <= 16`), but only via a Decimal-specific layout heuristic that
/// no corpus row pins — and it would not rescue the two cases above. Guessing
/// there would trade a flagged, understood gap for an unflagged one, so it is
/// deliberately not attempted. Reported as a concern instead.
/// `repr(abs(f))` for the float arm of the cardinal path.
///
/// `Num2Word_YO.to_cardinal` runs on `str(number)`, so the port needs the
/// exact text Python saw. The digits come from Rust's `{}` formatting —
/// shortest-round-trip, the same digit choice as CPython's `repr` — and the
/// *layout* (where the point goes, whether repr chose exponential form, the
/// `".0"` suffix on integral values) is recovered by the same [`py_str`] the
/// currency port already fuzzed against the interpreter.
///
/// `{}` never prints exponential form, so its output is normalised to
/// `(digits, scale)` first: an integral rendering like `"15000000000000000"`
/// carries positional trailing zeros that repr's mantissa would not
/// (`repr(1.5e16)` == `"1.5e+16"`), hence the trailing-zero strip. A
/// fractional rendering can never end in `'0'` — a shorter string would
/// round-trip to the same value, contradicting shortest-form — so the strip
/// only ever fires on the integral case.
///
/// Non-finite guards are defensive: the dispatcher's whole-float check
/// swallows `inf`/`nan` before Rust is reached (`int(inf)` raises in the
/// guard itself). Python's spellings are `"inf"`/`"nan"`, which then fail
/// `int()` exactly like a scientific literal (bug 13's family).
/// Python's `str(Decimal)` — the spec's *to-scientific-string* — for the
/// **absolute** value, from `BigDecimal`'s verbatim `(digits, scale)`.
///
/// This is *not* [`py_str`]: `Decimal.__str__` follows different rules from
/// float `repr`. Fixed notation applies iff `exponent <= 0` and the adjusted
/// exponent (`exponent + len(digits) - 1`) is `>= -6`; outside that the form
/// is exponential with a **capital `E`**, an explicit sign, and **no zero
/// padding** — `str(Decimal("1e-7"))` is `"1E-7"`, where a float repr would
/// be `"1e-07"`. Trailing coefficient zeros survive (`Decimal("1.10")` ->
/// `"1.10"`, `Decimal("1.50E-7")` -> `"1.50E-7"`) because `bigdecimal`
/// stores the parsed digits unnormalised. All spellings verified against the
/// live interpreter.
///
/// The dispatcher only forwards non-whole Decimals (`exponent < 0`), so the
/// `exponent > 0` positive-exponent arm (`"1E+2"`) is defensive — reachable
/// only by calling the core directly.