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
//! Port of `lang_BO.py` (Tibetan).
//!
//! Shape: **self-contained**. `Num2Word_BO` subclasses `Num2Word_Base` but
//! defines no `high_numwords`/`mid_numwords`/`low_numwords`, so Python's
//! `Num2Word_Base.__init__` never builds `self.cards` and never sets
//! `MAXVAL`. `to_cardinal` is overridden outright and drives a recursive
//! `_int_to_word`. Consequently `cards`/`maxval`/`merge` stay at their trait
//! defaults here, and there is **no overflow check and no ceiling at all** —
//! the top branch of `_int_to_word` recurses on `number // 10**8`
//! indefinitely, stacking "དུང་ཕྱུར་" once per 10^8 factor. `to_cardinal(10**21)`
//! is therefore "གཅིག་འབུམ་དུང་ཕྱུར་དུང་ཕྱུར་", not an `OverflowError`.
//!
//! `setup()` sets `negword = "མེད་ཆ་ "` (note the **trailing ASCII space**, which
//! is part of the literal) and `pointword = "ཚེག་"`.
//!
//! Inherited from `Num2Word_Base` but overridden by BO, so the trait defaults
//! are *not* used for any of the four in-scope modes:
//! * `to_cardinal` — own algorithm (below).
//! * `to_ordinal(n)` → `to_cardinal(n) + "པ་"`.
//! * `to_ordinal_num(n)` → `str(n) + "པ"` (BO overrides the base, which
//! returns the value unchanged).
//! * `to_year(n)` → `"སྤྱི་ལོ་" + to_cardinal(n)` (BO overrides the base, which
//! delegates to `to_cardinal`).
//!
//! # Behaviour worth flagging (reproduced verbatim, not fixed)
//!
//! 1. **No `verify_ordinal` call.** `Num2Word_Base.to_ordinal` would normally
//! be guarded by `verify_ordinal`, which raises `TypeError` on negatives.
//! BO's override skips it entirely, so `to_ordinal(-1000000)` happily
//! returns "མེད་ཆ་ གཅིག་ས་ཡ་པ་" — the negative-marker prefix with an ordinal
//! suffix glued on. Confirmed against the frozen corpus.
//! 2. **`to_year` prepends its era marker *outside* the sign.** Because
//! `to_year` is `"སྤྱི་ལོ་" + self.to_cardinal(val)` and `to_cardinal` emits the
//! negword itself, a negative year reads "སྤྱི་ལོ་" then "མེད་ཆ་ " — i.e.
//! `to_year(-500)` == "སྤྱི་ལོ་མེད་ཆ་ ལྔ་བརྒྱ་", with the era word preceding the
//! minus marker. Confirmed against the frozen corpus.
//! 3. **Asymmetric multiplier handling.** The `< 1000` branch indexes `ones`
//! directly (`ones[number // 100]`) while every branch above it recurses
//! (`self._int_to_word(number // 1000)` etc.). This is why 100 is
//! "གཅིག་བརྒྱ་" (an explicit "one hundred") and why the >= 10^8 branch can
//! nest "དུང་ཕྱུར་" arbitrarily deep.
//! 4. **`negword` is used raw, not stripped.** BO's `to_cardinal` does
//! `ret = self.negword` where `Num2Word_Base.to_cardinal` would do
//! `"%s " % self.negword.strip()`. Both happen to yield "མེད་ཆ་ " here
//! because the literal already carries exactly one trailing space, but the
//! literal is what is reproduced below.
//!
//! # The float / Decimal path
//!
//! BO does **not** override `to_cardinal_float`; it overrides `to_cardinal`
//! and handles non-integers inline. So `Num2Word_Base.to_cardinal_float` —
//! and with it `float2tuple` — is **never reached**, and none of that
//! machinery applies here:
//!
//! * **No `float2tuple`, so no f64 artefacts to preserve.** The base class
//! computes `post = abs(value - pre) * 10**precision` in binary f64 and
//! leans on a `< 0.01` heuristic to rescue `2.675` from `674.9999999999998`.
//! BO never does any float arithmetic at all: it reads the *digits of
//! `str(number)`*. `2.675` is "two point six seven five" because the
//! characters `6`, `7`, `5` are literally in `repr(2.675)`, not because a
//! rounding heuristic recovered them. `1.005` likewise.
//! * **No `round()`, so no banker's-rounding trap.** There is no rounding
//! anywhere on this path.
//! * **`self.precision` is never read**, so the `precision=` kwarg (issue
//! #580) is inert: `num2words(2.675, lang="bo", precision=1)` still emits
//! all three fractional digits. `precision_override` is accordingly ignored
//! — see [`LangBo::to_cardinal_float`].
//!
//! What the path *does* need is `str(number)`, byte for byte, because every
//! branch keys off it: the `"-"` prefix, the `"."`, and one word per
//! character of the fractional part. That makes the two `FloatValue` arms
//! genuinely different functions — `repr(float)` and `Decimal.__str__` are
//! separate CPython routines with separate exponent-notation rules — so
//! [`python_float_repr`] and [`python_decimal_str`] reproduce them
//! separately. Both are reconstructions, and their limits are documented on
//! each.
//!
//! Trailing zeros are the clearest proof that this is a string path rather
//! than a numeric one: `Decimal("1.10")` renders as "one point one zero"
//! because `str()` kept the zero, while `1.10` as a *float* renders as "one
//! point one" because `repr()` dropped it. A numeric port collapses the two.
//!
//! # Error variants
//!
//! For the four integer modes: none. Every in-scope path is total for integer
//! input: `_int_to_word` only ever indexes `ones`/`tens` with a value it has
//! already bounded to 0..=9, and the sign is stripped before recursion begins,
//! so no `IndexError`, `KeyError` or `ValueError` site exists. There is no
//! `MAXVAL`, hence no `OverflowError` either.
//!
//! The currency surface adds two, both detailed below: `NotImplementedError`
//! from `to_cheque` on an unknown code, and `ValueError` from `_split_currency`
//! when `str(val)` came out in exponent notation.
//!
//! The float path adds one more, for the same underlying reason: `int()` is
//! fed raw characters of `str(number)`, so any value whose `str()` went
//! scientific raises **`ValueError`** rather than converting. See
//! [`int_token`].
//!
//! # The currency surface
//!
//! `Num2Word_BO` declares `CURRENCY_FORMS` for exactly three codes (CNY, USD,
//! EUR) and overrides `to_currency` outright. It inherits `CURRENCY_ADJECTIVES`
//! and `CURRENCY_PRECISION` from `Num2Word_Base`, where **both are empty** — so
//! `CURRENCY_PRECISION.get(code, 100)` is 100 for *every* code and the trait
//! defaults for `currency_precision`/`currency_adjective` are already correct.
//! This is why BO has no 3-decimal or 0-decimal behaviour: `to_currency("KWD")`
//! divides by 100, not 1000, and `to_currency("JPY", 12.34)` still renders a
//! cents segment rather than rounding to a whole unit. Confirmed against the
//! frozen corpus for both codes.
//!
//! `to_cheque` is *not* overridden, so `Num2Word_Base.to_cheque` runs verbatim
//! — which means the two halves of the surface disagree about unknown codes:
//!
//! * `to_currency` does `CURRENCY_FORMS.get(currency, CURRENCY_FORMS["CNY"])`
//! and so **silently falls back to CNY** — `to_currency(1, currency="GBP")`
//! is "གཅིག་ སྒོར་", never an error.
//! * `to_cheque` does `CURRENCY_FORMS[currency]` and so raises
//! `NotImplementedError` for the very same code.
//!
//! Both are reproduced: [`LangBo::to_currency`] resolves the fallback itself,
//! while `currency_forms` returns `None` for an unknown code so that the
//! trait's default `to_cheque` (== `default_to_cheque`, a faithful port of the
//! base method) raises. Corpus: `currency:GBP` succeeds with CNY words,
//! `cheque:GBP` raises `NotImplementedError`.
//!
//! ## `parse_currency` does not exist
//!
//! `Num2Word_BO.to_currency` opens with
//!
//! ```text
//! try:
//! left, right, is_negative = self.parse_currency(val)
//! except AttributeError:
//! ...
//! ```
//!
//! No `parse_currency` method is defined anywhere in num2words2 — not on
//! `Num2Word_BO`, not on `Num2Word_Base` (`currency.py` exports the free
//! function `parse_currency_parts`, which is a different name and never bound
//! to the instance). The attribute lookup therefore *always* raises
//! `AttributeError`, the `try` body never completes, and the `except` branch is
//! the only live path. It is ported as straight-line code with no error plumbing,
//! because the exception is unconditional and always swallowed.
use crate;
use crate;
use crateFloatValue;
use crate;
use BigDecimal;
use BigInt;
use ;
use HashMap;
/// `_int_to_word`'s early return for 0.
const ZERO_WORD: &str = "ཀླད་ཀོར་";
/// `setup(): self.negword` — the trailing ASCII space is part of the literal.
const NEGWORD: &str = "མེད་ཆ་ ";
/// `setup(): self.pointword`.
const POINTWORD: &str = "ཚེག་";
/// `to_year`'s era prefix.
const YEAR_PREFIX: &str = "སྤྱི་ལོ་";
/// `Num2Word_BO.to_currency`'s own default `separator=" དང་ "`.
///
/// See [`SEPARATOR_UNSET`] for why this cannot simply be a parameter default.
const SEPARATOR_DEFAULT: &str = " དང་ ";
/// The separator the pyo3 binding passes when the Python caller omitted one.
///
/// `Num2Word_BO.to_currency` declares `separator=" དང་ "`, but the `Lang` trait
/// has no per-language defaults: `__init__.py`'s currency fast path (and
/// `diff_test.py`) substitute `kwargs.get("separator", ",")` — **`Num2Word_Base`'s**
/// default — before the value ever reaches Rust. By then "caller omitted
/// separator" and "caller explicitly passed a comma" are the same string, and
/// the information needed to tell them apart no longer exists on this side of
/// the boundary.
///
/// So `,` is read back as the unset sentinel and BO's own default restored.
/// This is the only reading that matches the oracle: every float row of the
/// `bo` currency corpus was generated by `num2words(v, lang="bo",
/// to="currency", currency=c)` with no `separator=`, and every one of them
/// expects " དང་ ".
///
/// The cost is narrow and known: a caller who *explicitly* passes
/// `separator=","` gets " དང་ " here where Python would give ",". Fixing that
/// properly needs `Option<&str>` in the trait signature, which lives in
/// `base.rs` — outside this port's remit. Flagged in the port report. This
/// mirrors the convention `lang_ca.rs` established for the same problem.
const SEPARATOR_UNSET: &str = ",";
/// `to_currency`'s fallback code: `CURRENCY_FORMS.get(currency, CURRENCY_FORMS["CNY"])`.
///
/// Note the Python evaluates `self.CURRENCY_FORMS["CNY"]` *eagerly* as the
/// `.get` default, so a class that dropped the CNY entry would raise `KeyError`
/// on every call. BO always has it, so the lookup below is infallible.
const FALLBACK_CURRENCY: &str = "CNY";
/// `to_ordinal`'s suffix (note the trailing tsheg).
const ORDINAL_SUFFIX: &str = "པ་";
/// `to_ordinal_num`'s suffix (note: **no** trailing tsheg, unlike `to_ordinal`).
const ORDINAL_NUM_SUFFIX: &str = "པ";
/// `ones`, index 0..=9. Index 0 is the empty string in Python.
const ONES: = ;
/// `tens`, index 0..=9 (the multiple-of-ten words). Index 0 is the empty
/// string in Python and is unreachable (the `< 10` branch catches it first).
const TENS: = ;
/// The hundreds word, spliced between `ones[number // 100]` and the remainder.
const HUNDRED: &str = "བརྒྱ་";
/// The scale branches above 1000, in the exact order of Python's `elif` chain.
///
/// Each entry is `(limit_exp, div_exp, word)` standing for Python's
/// `elif number < 10**limit_exp: _int_to_word(number // 10**div_exp) + word +
/// (_int_to_word(number % 10**div_exp) if number % 10**div_exp else "")`.
///
/// The final entry (`10^8`, "དུང་ཕྱུར་") is Python's unguarded `else` arm; its
/// `limit_exp` is never consulted, which is what makes the recursion
/// unbounded. See [`int_to_word`].
const SCALES: = ;
/// `10**exp` as a `BigInt`.
/// Narrow a `BigInt` the caller has already bounded to 0..=999.
///
/// Every call site sits behind a `n < 1000` comparison that proves the range,
/// so the `expect` is unreachable rather than a lurking panic. Below 1000 the
/// arithmetic is done in `usize`: the values are provably bounded, and
/// Python's `//`/`%` agree with Rust's `/`/`%` on non-negatives.
/// Port of `Num2Word_BO._int_to_word`.
///
/// Only ever reached with a non-negative value: `to_cardinal` strips the
/// leading "-" from the *string* before calling `int()`, so the sign never
/// arrives here. (Were it to, Python's negative list indexing would silently
/// wrap — `ones[-1]` == "དགུ་" — but that path is unreachable for the four
/// in-scope modes.)
///
/// Recursion depth is `O(log_1e8(n))`, so even a 10^606 input nests only ~76
/// deep — no fixed-width cast is needed or made anywhere.
/// Python's `int(token)`, for the tokens `to_cardinal` actually feeds it.
///
/// `to_cardinal` never validates: it hands `int()` whatever slice of
/// `str(number)` it carved out, and lets the exception escape. The reachable
/// tokens all come from `repr(float)` or `Decimal.__str__` with at most one
/// leading `"-"` already peeled off, so their alphabet is
/// `[0-9] . - + e E i n f a`. Over that alphabet "every character is an ASCII
/// digit" is exactly Python's accept condition, and everything else raises
/// `ValueError` with the token quoted verbatim — `'e'`, `'1e+16'`, `'1E-7'`,
/// `'inf'`, `'nan'`.
///
/// The wider `int()` grammar (surrounding whitespace, a `+`/`-` sign,
/// `1_000` underscores, non-ASCII decimal digits like `'٥'`) is deliberately
/// *not* implemented: none of it is reachable from a `str()` of a float or a
/// Decimal, and accepting it would only paper over inputs Python rejects. The
/// argument does not actually depend on the alphabet being complete — a
/// `Decimal("Infinity")` would widen it, though `BigDecimal::from_str` rejects
/// that at the shim before it can — only on none of these sources emitting
/// the sign/space/underscore forms `int()` accepts and this rejects. None do.
/// CPython's `repr(float)` — what `str(number)` returns for a `float`.
///
/// `precision` is the shim's `abs(Decimal(repr(value)).as_tuple().exponent)`,
/// i.e. the number of fractional digits `repr` emitted. Its whole purpose is
/// to keep shortest-round-trip digit selection on the Python side, so the
/// fixed-notation branch just asks for exactly that many digits:
/// `{:.p$}` is correctly-rounded fixed formatting, and the nearest
/// `p`-digit decimal to the double *is* `repr`. (No tie can split them: a tie
/// would mean the double sits exactly halfway between two `p`-digit decimals,
/// which forces `repr` to spend a `p+1`-th digit and contradicts `p`.)
///
/// # The one thing that must be reimplemented
///
/// `repr` switches to exponent notation, and `precision` cannot reveal when:
/// `repr(1e-05)` is `'1e-05'` and `repr(0.00012)` is `'0.00012'`, and both
/// report `precision == 5`. CPython decides in `format_float_short`:
///
/// ```text
/// case 'r': /* convert to exponential format at 1e16. This is used for repr. */
/// if (decpt <= -4 || decpt > 16)
/// use_exp = 1;
/// ```
///
/// where `decpt` positions the decimal point against the *shortest* digits
/// (`value == 0.<digits> * 10**decpt`). Reading `decpt` back out would mean
/// reimplementing the digit selection this function exists to avoid — but the
/// test collapses to a comparison on the value itself:
///
/// * `decpt > 16` ⟺ `|v| >= 1e16`. A shortest decimal `D < 10**16` can only
/// round to a double `>= 10**16` if that double *is* `1e16` (doubles are
/// spaced 2 apart there, and `float("9999999999999999")` ties to even and
/// lands on it) — and `1e16`'s own shortest form is the 1-digit `"1"` with
/// `decpt == 17`, so `decpt <= 16` never survives.
/// * `decpt <= -4` ⟺ `0 < |v| < 1e-4`. The double nearest `1e-4` sits just
/// *above* it, so no `D >= 10**-4` rounds below the boundary and vice
/// versa.
/// * `v == 0.0` is neither: CPython's dtoa reports `decpt == 1` for zero, so
/// `repr(0.0)` is the fixed `'0.0'` (and `repr(-0.0)` is `'-0.0'`, a sign
/// `{:.1}` preserves and `is_negative()` would not).
///
/// Checked against CPython over 608,900 doubles — random bit patterns plus
/// 300-step `nextafter` walks either side of `1e16`, `1e-4`, `1e-5`, `1e15`,
/// `1e17`, `1e23`, `5e-324` and `f64::MAX` — with zero divergence.
///
/// The exponent branch then reuses Rust's `{:e}`, whose mantissa is already
/// normalised to one leading digit exactly like CPython's; only the exponent
/// spelling differs (`e16` vs `e+16`, `e-5` vs `e-05`). That branch *does*
/// lean on Rust and CPython agreeing on the shortest digits, which the same
/// 608,900-value run confirms. Every value reaching it raises `ValueError`
/// regardless (see [`int_token`]) — the digits only pick which token the
/// message quotes.
/// CPython's `Decimal.__str__` — what `str(number)` returns for a `Decimal`.
///
/// A transcription of `_pydecimal.Decimal.__str__`, which works off the
/// coefficient digits and the exponent rather than the value:
///
/// ```python
/// leftdigits = self._exp + len(self._int)
/// if self._exp <= 0 and leftdigits > -6:
/// dotplace = leftdigits # no exponent required
/// else:
/// dotplace = 1 # scientific: 1 digit left of the point
/// ...
/// if leftdigits == dotplace: exp = ''
/// else: exp = 'E%+d' % (leftdigits - dotplace)
/// ```
///
/// `BigDecimal::as_bigint_and_exponent` hands back exactly the pair Python
/// stores — `scale` is the negation of `_exp`, and the coefficient keeps its
/// significant digits verbatim, trailing zeros included (`"1.10"` is 110×10⁻²
/// on both sides, `"0.00"` is 0×10⁻²). That fidelity is the whole reason this
/// is reconstructed rather than delegated: **`BigDecimal`'s own `Display` is
/// not `str(Decimal)`.** It prints `"0.00"` as `"0"` (dropping a scale Python
/// keeps, which would silently eat two fractional words) and `"1E+16"` as
/// lowercase `"1e+16"` (Python emits uppercase `E`, and that string is quoted
/// verbatim in the `ValueError` this value raises).
///
/// Note the thresholds differ from [`python_float_repr`]'s: `Decimal` goes
/// scientific whenever `_exp > 0` or `leftdigits <= -6`, so `Decimal("1E+16")`
/// stringifies as `'1E+16'` and raises where the numerically equal
/// `Decimal(10**16)` stringifies as plain digits and converts. Reproducing
/// `repr(float)`'s rule here instead would be wrong in both directions.
///
/// # Known gap: negative zero
///
/// `str(Decimal("-0.0"))` is `'-0.0'`, so BO emits its negword. `BigInt` has
/// no signed zero, so `BigDecimal::from_str("-0.0")` arrives here as `+0`
/// scale 1 and the sign is already gone — this returns `"0.0"` and the negword
/// is dropped. The sign is lost at the boundary, before this function runs, so
/// it cannot be recovered here. Flagged in the port report; not in the corpus.
/// `str(number)` as `Num2Word_BO.to_cardinal` sees it.
///
/// The `FloatValue` split is exactly the `float`/`Decimal` split CPython makes
/// when choosing which `__str__`/`__repr__` to run, so it maps straight onto
/// the two reconstructions.
/// Port of `Num2Word_BO._split_currency`, applied to `abs(val)`.
///
/// ```text
/// def _split_currency(self, n):
/// parts = str(n).split(".")
/// left = int(parts[0]) if parts[0] else 0
/// right = int(parts[1][:2].ljust(2, "0")) if len(parts) > 1 and parts[1] else 0
/// return left, right
/// ```
///
/// This is a *string* operation on `str(n)`, so the port has to reproduce what
/// `str()` would have produced rather than just doing decimal arithmetic:
///
/// * **`CurrencyValue::Int`** — `str(int)` is plain digits with no "." and no
/// exponent at any magnitude, so `parts` has one element: `left` is the
/// integer, `right` is 0. An int therefore never shows cents, which is the
/// `isinstance(val, int)` distinction the boundary preserves.
///
/// * **`CurrencyValue::Decimal`** — the `BigDecimal` was parsed from the exact
/// `str(value)` the Python side produced, so its digits *are* the characters
/// Python split on. For any plain-decimal `str()`, Python's
/// `int(parts[1][:2].ljust(2, "0"))` — take the first two fractional digits,
/// right-pad with zeros — is exactly `floor(frac * 100)`, which is what the
/// truncating arithmetic below computes:
///
/// | `str(n)` | `parts[1][:2].ljust(2,"0")` | `right` | `floor(frac*100)` |
/// |---|---|---|---|
/// | `"12.34"` | `"34"` | 34 | 34 |
/// | `"0.5"` | `"50"` | 50 | 50 |
/// | `"1.0"` | `"00"` | 0 | 0 |
/// | `"0.001"` | `"00"` | 0 | 0 |
/// | `"0.567"` | `"56"` | 56 | 56 |
///
/// The `ljust` and the `[:2]` truncation are both subsumed: `BigDecimal`
/// carries the trailing zeros of `"1.0"` in its scale, and `with_scale(0)`
/// truncates rather than rounds (`99.99 -> 99`), matching `[:2]` discarding
/// the third digit instead of rounding on it.
///
/// # The exponent-notation `ValueError`
///
/// `str()` switches to exponent notation for a float outside roughly
/// `1e-4 <= |v| < 1e16`, and `int()` chokes on the resulting token:
/// `str(1e16)` is `"1e+16"`, `parts` is `["1e+16"]`, and `int("1e+16")` raises
/// **`ValueError`**. (`str(1.5e16)` is `"1.5e+16"`, where `parts[1][:2]` is
/// `"5e"` and `int("5e")` raises `ValueError` too — same exception, different
/// token.) So the whole function raises for large floats rather than returning
/// anything.
///
/// The check below keys off the *representation*, which is the same thing
/// Python's `str().split(".")` does, so it stays faithful for `Decimal` inputs
/// too (the shim accepts those alongside floats): `Decimal("1E+16")` stringifies
/// with an exponent and raises, while `Decimal(10**16)` stringifies as plain
/// digits and succeeds — and the two parse to different scales here (-16 vs 0),
/// so both are handled correctly.
///
/// A **positive** exponent is therefore recoverable: plain decimal notation can
/// never yield a negative `BigDecimal` scale, so `scale < 0` proves `str()`
/// emitted an exponent, and the `ValueError` is raised here. Verified against
/// CPython: the message matches `int("1e+16")`'s byte for byte.
///
/// A **negative** exponent is not recoverable, and this is the one known gap.
/// `str(1e-05)` is `"1e-05"` (CPython goes scientific below `1e-4`) and raises,
/// but it parses to the very same `(1, scale=5)` as `Decimal("0.00001")`, which
/// stringifies as `"0.00001"` and does *not* raise. The two are indistinguishable
/// once across the boundary, so a float `< 1e-4` silently returns `(0, 0)` here
/// where Python raises `ValueError`. Discriminating on the value instead
/// (`|v| < 1e-4`) would fix the float and break the `Decimal`, so the
/// representation-faithful rule is kept and the gap is flagged in the report
/// rather than papered over. Reproducing it properly needs `repr(float)`, which
/// `currency.rs` deliberately keeps on the Python side.