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
//! Port of `lang_LO.py` (Lao).
//!
//! Shape: **self-contained**. `Num2Word_LO` subclasses `Num2Word_Base`, but its
//! `setup()` defines only `negword`, `pointword` and an `ones` list — no
//! `high_numwords`/`mid_numwords`/`low_numwords`. The `any(hasattr(...))` guard
//! in `Num2Word_Base.__init__` therefore never fires, so Python never builds
//! `self.cards` and never sets `self.MAXVAL`. `to_cardinal` is overridden
//! outright and drives `_int_to_word`, a plain recursive descent over the Lao
//! myriad-style scale (สิบ/ຊາວ/ຮ້ອຍ/ພັນ/ໝື່ນ/ແສນ/ລ້ານ).
//!
//! Consequently `cards`/`maxval`/`merge` stay at their trait defaults here, and
//! there is **no overflow check at all** — see bug 1 below for what happens
//! instead.
//!
//! Inherited from `Num2Word_Base` and *not* overridden by LO:
//! * `to_cheque` — the only inherited method that runs. It reads
//! `CURRENCY_FORMS[currency]` *strictly* (`KeyError` -> `NotImplementedError`)
//! and `_money_verbose` -> `to_cardinal`, both of which the trait defaults
//! already provide. See bug 5 for the contradiction this creates with LO's
//! own `to_currency`.
//! * `verify_ordinal` is inherited but **never called**, which is why
//! negatives sail through `to_ordinal` (bug 2).
//! * `pluralize`, `_cents_verbose` and `_cents_terse` are all unreachable —
//! LO's `to_currency` never calls them and `to_cheque` does not either — so
//! their trait defaults (`pluralize` raises) are deliberately left alone.
//!
//! # Currency
//!
//! `CURRENCY_FORMS` is defined on `Num2Word_LO` itself (LAK/USD/EUR), so none of
//! the `lang_EUR`/`Num2Word_EN` shared-dict mutation described in
//! `PORTING_CURRENCY.md` applies here — the live interpreter confirms exactly
//! those three codes. `CURRENCY_PRECISION` and `CURRENCY_ADJECTIVES` are both
//! empty (`{}`), so every code is divisor 100 and no adjective exists; the trait
//! defaults cover both and neither hook is overridden.
//!
//! `to_currency` is overridden outright and shares no code with
//! `Num2Word_Base.to_currency`: no `parse_currency_parts`, no divisor, no
//! `pluralize`. It re-splits `str(val)` by hand.
//!
//! # Faithfully reproduced Python bugs
//!
//! This is a port, not a rewrite. Each of the following is wrong-looking but is
//! exactly what Python emits, and each is pinned by the frozen corpus:
//!
//! 1. **`_int_to_word` gives up at 10^9 and returns the decimal digits.** The
//! final `else` arm is `return str(number)`, so `to_cardinal(10**9)` is the
//! ASCII string `"1000000000"`, not Lao words. Every value >= 10^9 is echoed
//! back as digits, forever — there is no `OverflowError` and no upper bound.
//! Corpus confirms this out to 10^21. See [`LangLo::int_to_word`].
//! 2. **`to_ordinal` never calls `verify_ordinal`**, so negatives are accepted
//! and produce `"ທີ່" + to_cardinal(n)` — e.g. `to_ordinal(-1)` ==
//! `"ທີ່ລົບ ໜຶ່ງ"` ("th-minus one"). Most languages raise `TypeError` here.
//! 3. **`to_ordinal`/`to_ordinal_num` are pure prefixing** — the "ordinal" is
//! just `"ທີ່"` glued onto the cardinal (or onto `str(number)`), with no
//! separator and no morphology. So `to_ordinal(10**9)` == `"ທີ່1000000000"`,
//! inheriting bug 1.
//! 4. **`negword` carries a trailing space** (`"ລົບ "`, not `"ລົບ"`), unlike the
//! base class's convention of stripping it at the call site. `to_cardinal`
//! concatenates it raw, which happens to give the right single space —
//! but it means [`Lang::negword`] here returns a *space-suffixed* word, so a
//! caller applying the base's usual `"%s " % negword.strip()` idiom would
//! get the same result only by coincidence. `to_currency` concatenates it
//! raw too.
//! 5. **`to_currency` and `to_cheque` disagree about unknown currency codes.**
//! LO's `to_currency` looks the code up *leniently* —
//! `CURRENCY_FORMS.get(currency, self.CURRENCY_FORMS["LAK"])` — so an
//! unimplemented code silently renders in **Lao kip**, while the inherited
//! `to_cheque` does a strict `CURRENCY_FORMS[currency]` and raises
//! `NotImplementedError` for the very same code. The corpus pins both halves:
//! `currency:GBP` -> `"ສິບສອງ ກີບ ສາມສິບສີ່ ອັດ"` (kip/at, not pounds/pence)
//! while `cheque:GBP` -> `NotImplementedError`. Same for JPY, KWD, BHD, INR,
//! CNY and CHF. See [`LangLo::to_currency`].
//! 6. **`to_currency` ignores `CURRENCY_PRECISION` entirely.** It hardcodes a
//! two-digit subunit via `parts[1][:2]`, so the 3-decimal (KWD/BHD) and
//! 0-decimal (JPY) currencies get plain hundredths like everything else —
//! and since those codes are not in `CURRENCY_FORMS` anyway they land on the
//! LAK fallback first. `currency:JPY` of `0.5` is `"ສູນ ກີບ ຫ້າສິບ ອັດ"`, not
//! the whole-unit rounding `Num2Word_Base.to_currency` would apply. LO's
//! `CURRENCY_PRECISION` is `{}` regardless, so `to_cheque` uses 100.
//! 7. **A float with zero cents drops the cents segment.** The guard is
//! `if cents and right`, and `right` is an int, so `1.0` (which yields
//! `right = 0`) renders `"ໜຶ່ງ ເອີໂຣ"` — identical to the int `1`.
//! `Num2Word_Base.to_currency` would emit a "zero cents" tail here. The
//! int/float distinction is still threaded through faithfully (see
//! [`split_currency`]) because it only *coincidentally* collapses in LO's
//! output.
//! 8. **`cents=False` omits the cents rather than making them terse**, because
//! the same `cents and right` guard suppresses the whole segment instead of
//! switching to `_cents_terse` the way the base class does.
//! 9. **`adjective` is accepted and completely ignored** — declared in the
//! signature, never read, and `CURRENCY_ADJECTIVES` is empty anyway.
//! 10. **Subunits are truncated, not rounded.** `parts[1][:2]` slices the
//! decimal string, so `12.349` gives 34 cents (not 35) and `0.001` gives 0.
//!
//! # Non-bugs that look like bugs
//!
//! * The trailing `.strip()` in `to_cardinal` is a no-op for integer input:
//! every `_int_to_word` arm returns a non-empty, non-padded string and the
//! only prefix is `""` or `"ລົບ "`. Reproduced anyway ([`str::trim`]) so the
//! port matches the source line for line.
//! * The `if number < 0` arm of `_int_to_word` is **dead code** on the four
//! in-scope entry points: `to_cardinal` strips the sign before calling, and
//! every recursive call passes a non-negative quotient or remainder. It is
//! reachable only from `to_currency` (out of scope). Ported regardless.
//! * `to_cardinal`'s `"." in n` branch (the `pointword` per-digit path) is
//! unreachable from `BigInt` input — `str(int)` never contains a dot. The
//! `BigInt` `to_cardinal` above therefore only runs the integer `else` branch.
//! The dotted branch *is* ported, in [`LangLo::to_cardinal_float`]: because
//! `Num2Word_LO` overrides `to_cardinal` and handles non-integers inline via
//! `str(number)` string-splitting — nothing like `Num2Word_Base`'s
//! `float2tuple` — the trait's default `to_cardinal_float` is wrong for LO and
//! is overridden. See that method for the full port and its consequences.
//!
//! # Float routing: every float/Decimal goes through the string surgery
//!
//! `to_cardinal` branches on `"." in str(number)`, never on
//! `int(value) == value`, so a *whole* float still reads its trailing zero:
//! `to_cardinal(5.0)` == `"ຫ້າ ຈຸດ ສູນ"` and `Decimal("5.00")` reads two zero
//! digits, while a point-free `Decimal("5")` takes the integer reading. The
//! base trait's `cardinal_float_entry` (whole -> int path) is therefore
//! overridden to send **all** float/Decimal input through the cascade;
//! `to_ordinal`/`to_year` float entries prefix that same output
//! (`"ທີ່"`/`"ປີ "`), and `to_ordinal_num`'s float entry prefixes the
//! binding-provided `str(value)`.
//!
//! `str(number)` is rebuilt exactly: `str(Decimal)` via
//! [`crate::strnum::python_decimal_str`] (trailing zeros and exponent forms
//! kept — `"5.00"`, `"1E+2"`), and `str(float)` via [`py_float_str`], which
//! mirrors CPython's shortest-repr formatting *including* the switch to
//! exponent form at `|v| >= 1e16` or `0 < |v| < 1e-4`. Exponential text then
//! fails in `int()` exactly as Python's does: `int("1e+16")` / `int("1E+2")`
//! raise ValueError (no dot in the repr), and a mantissa-dotted `1.23e+16`
//! dies on `int("e")` in the digit walk. `Decimal("-0.0")` arrives as
//! `FloatValue::Float { -0.0 }` (the binding converts it — `BigDecimal` has
//! no signed zero) and the sign bit keeps the negword:
//! `"ລົບ ສູນ ຈຸດ ສູນ"`, as pinned.
//!
//! # String input: Infinity/NaN raise ValueError, not OverflowError
//!
//! `num2words("Infinity", lang="lo")` parses to `Decimal("Infinity")` and
//! lands in this `to_cardinal`: `str()` gives `"Infinity"` — no `"."` — and
//! `int("Infinity")` raises **ValueError**. The binding would otherwise map
//! `ParsedNumber::Inf` to the base path's OverflowError before any LO code
//! runs, so [`Lang::str_to_number`] intercepts Inf (and NaN, whose binding
//! message differs from `int("NaN")`'s). Known gap (unpinned): Python's
//! `to_ordinal_num(Decimal("Infinity"))` echoes `"ທີ່Infinity"`, which the
//! entry-level interception turns into the cardinal path's ValueError; the
//! strings corpus pins Infinity/NaN under `to=cardinal` only.
//!
//! # Error variants
//!
//! **The four integer modes raise nothing.** No `MAXVAL` check, no dict lookups,
//! no list indexing that can run out of range (every `ones[...]` index is pinned
//! to 0..=9 by the branch guard that precedes it), and no `int()` of a
//! non-numeric token. Every *integer* corpus row for `lo` in those modes is
//! `"ok": true`. The float/Decimal side of cardinal/ordinal/year raises
//! `Value` — Python's ValueError from `int()` — exactly when `str(number)`
//! is exponential (see the float-routing section above).
//!
//! The currency surface has exactly two:
//!
//! * `NotImplemented` — from the inherited `to_cheque` only, on a code outside
//! {LAK, USD, EUR}. Message: `Currency code "X" not implemented for
//! "Num2Word_LO"`. **`to_currency` cannot raise it** (bug 5).
//! * `Value` — from `int()` on an exponent-notation token inside
//! [`split_currency`]; see that function for the exact conditions and the one
//! known gap.
use crate;
use crate;
use crateFloatValue;
use crate;
use BigDecimal;
use BigInt;
use ;
use HashMap;
use FromStr;
/// `self.ones`, indices 0..=9. Every read is guarded by a range check that
/// pins the index into this table, so there is no `IndexError` path.
const ONES: = ;
/// `self.negword`. Note the trailing space — see bug 4 in the module docs.
const NEGWORD: &str = "ລົບ ";
/// `self.pointword`. Reachable only via the float/Decimal path — `str(int)`
/// never contains the dot that gates it.
const POINTWORD: &str = "ຈຸດ";
/// 10 — a standalone word, not `ones[1] + ສິບ`.
const TEN: &str = "ສິບ";
/// 20 — likewise standalone, and the reason 20..=29 gets its own arm.
const TWENTY: &str = "ຊາວ";
/// Scale suffixes: 10^2, 10^3, 10^4, 10^5, 10^6.
const HUNDRED: &str = "ຮ້ອຍ";
const THOUSAND: &str = "ພັນ";
const TEN_THOUSAND: &str = "ໝື່ນ";
const HUNDRED_THOUSAND: &str = "ແສນ";
/// 10^6. Unlike the smaller scales this one is joined with a **leading space**
/// (`" ລ້ານ"`), which is why `to_cardinal(10**6)` == `"ໜຶ່ງ ລ້ານ"` while
/// `to_cardinal(1000)` == `"ໜຶ່ງພັນ"` (no space).
const MILLION: &str = " ລ້ານ";
/// The ordinal prefix, glued on with no separator.
const ORDINAL_PREFIX: &str = "ທີ່";
/// The year prefix, which *does* carry a trailing space.
const YEAR_PREFIX: &str = "ປີ ";
/// `Num2Word_LO.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_LO.to_currency` declares `separator=" "`, but the `Lang` trait has
/// no per-language defaults: `__init__.py`'s currency fast path (and
/// `bench/diff_test.py`) both 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 LO's own default restored.
/// This is the only reading that matches the oracle: every float row of the `lo`
/// currency corpus was generated by `num2words(v, lang="lo", to="currency",
/// currency=c)` with no `separator=`, and every one of them expects `" "` —
/// taking the comma at face value would render `"ສິບສອງ ເອີໂຣ,ສາມສິບສີ່ ເຊັນ"`
/// and fail all 63 of them. It is also what the *shipped* shim needs: a plain
/// `num2words(12.34, lang="lo", to="currency", currency="EUR")` must not start
/// emitting commas just because the fast path took over.
///
/// 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` / `lang_bo.rs` / `lang_as.rs` established
/// for the same problem.
const SEPARATOR_UNSET: &str = ",";
/// `to_currency`'s fallback code: `CURRENCY_FORMS.get(currency, CURRENCY_FORMS["LAK"])`.
///
/// Note Python evaluates `self.CURRENCY_FORMS["LAK"]` *eagerly* as the `.get`
/// default, so a class that dropped the LAK entry would raise `KeyError` on
/// every call. LO always has it, so the lookup below is infallible.
const FALLBACK_CURRENCY: &str = "LAK";
/// `self.ones[i]` where the caller has already proven `0 <= i <= 9`.
///
/// The conversion cannot fail: each call site is dominated by a comparison
/// bounding the value to a single decimal digit.
/// The `(left, right)` split inlined at the top of `Num2Word_LO.to_currency`.
///
/// ```text
/// is_negative = False
/// if val < 0:
/// is_negative = True
/// val = abs(val)
///
/// parts = str(val).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
/// ```
///
/// (Byte for byte the body of `Num2Word_BO._split_currency`, which `lang_bo.rs`
/// ports the same way. The sign is handled by the caller; this takes `abs`.)
///
/// # Why this is arithmetic and not string surgery
///
/// The Python operates on `str(val)`, but the string is gone by the time the
/// value reaches Rust — `currency.rs` deliberately keeps `repr(float)` on the
/// Python side and hands over a parsed `BigDecimal`. The arithmetic below is
/// nonetheless *exactly* equivalent, because `BigDecimal` retains the scale of
/// the literal it was parsed from:
///
/// * `int(parts[0])` is the truncated integer part, and `with_scale(0)` divides
/// by a power of ten with `BigInt` division, i.e. truncates toward zero. `val`
/// is already non-negative here, so truncation is the floor.
/// * `int(parts[1][:2].ljust(2, "0"))` is `floor(frac * 100)`. The `[:2]`
/// truncation and the `ljust` zero-padding are both subsumed: the scale
/// carries `"1.0"`'s trailing zero, and truncating at two places is what
/// discarding the third digit does.
///
/// | `str(val)` | `parts[1][:2].ljust(2,"0")` | Python | `floor(frac*100)` |
/// |---|---|---|---|
/// | `"1.0"` | `"00"` | 0 | 0 |
/// | `"0.5"` | `"50"` | 50 | 50 |
/// | `"0.01"` | `"01"` | 1 | 1 |
/// | `"12.34"` | `"34"` | 34 | 34 |
/// | `"99.99"` | `"99"` | 99 | 99 |
/// | `"0.001"` | `"00"` | 0 | 0 |
/// | `"0.567"` | `"56"` | 56 | 56 |
///
/// `parts[0]` is never `""` and `parts[1]` is never `""` for any string Python's
/// `str()` produces, so the two `else 0` fallbacks are dead; they coincide with
/// the arithmetic anyway.
///
/// # 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`** — not `NotImplementedError`, and not anything LO catches. So
/// `to_currency` raises for large floats rather than returning a string.
///
/// The check below keys off the *representation*, which is what Python's
/// `str().split(".")` does too, so it stays faithful for the `Decimal` inputs the
/// shim also accepts: `Decimal("1E+3")` stringifies with an exponent and raises,
/// while `Decimal(1000)` stringifies as plain digits and succeeds — and the two
/// parse to different scales (-3 vs 0), so both land 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. No false positives are possible.
///
/// Two exponent cases are **not** recoverable. Both are flagged in the port
/// report rather than papered over, and no corpus row exercises either.
///
/// 1. *Negative exponent.* `str(1e-05)` is `"1e-05"` (CPython goes scientific
/// below `1e-4`) and raises `ValueError`, but it parses to the very same
/// `(1, scale=5)` as `Decimal("0.00001")`, which stringifies as `"0.00001"`
/// and does *not* raise — Python returns `"ສູນ ເອີໂຣ"` for it. The two are
/// indistinguishable once across the boundary, so a float `< 1e-4` returns
/// `(0, 0)` here (`"ສູນ ເອີໂຣ"`) where Python raises. Discriminating on the
/// value instead (`|v| < 1e-4`) would fix the float and break the `Decimal`,
/// so the representation-faithful rule is kept.
///
/// 2. *Exponent absorbed by the mantissa's own digits.* When a float's repr
/// carries at least as many fractional digits as its exponent the scale
/// comes out `>= 0` and no error fires — but Python does not error either.
/// It splits the **exponent string** on the dot and parses the pieces:
/// `str(1.2345678901234568e+16).split(".")` is
/// `["1", "2345678901234568e+16"]`, so `left = int("1") = 1` and
/// `right = int("23") = 23`, giving `"ໜຶ່ງ ເອີໂຣ ຊາວສາມ ເຊັນ"` — one euro
/// and twenty-three cents for a value of ~1.2e16. This port instead reads
/// the number it was handed and returns `"12345678901234568 ເອີໂຣ"` (bug 1's
/// digit echo). Reproducing Python's answer would mean re-deriving
/// `repr(float)` in Rust, which `currency.rs` deliberately keeps on the
/// Python side; the divergence only affects floats `>= 1e16`, where Python's
/// own output is nonsense.
/// Python's `str(float)` for a finite-or-not f64, sign included.
///
/// CPython's `float.__str__` is the shortest round-trip repr, printed in
/// fixed notation while the decimal point sits in `-3 <= decpt <= 16` and in
/// exponent notation outside it — i.e. e-form iff `|v| >= 1e16` or
/// `0 < |v| < 1e-4` (`str(1e16)` == `"1e+16"`, `str(1e15)` ==
/// `"1000000000000000.0"`, `str(0.0001)` == `"0.0001"`, `str(1e-05)` ==
/// `"1e-05"`).
///
/// * **Fixed form** — `format!("{:.*}", precision, mag)`: `precision` is the
/// repr-derived fractional digit count the binding carried over
/// (`abs(Decimal(repr(v)).as_tuple().exponent)`), and correctly rounding
/// the *exact* f64 to that many places reproduces the shortest-repr digits
/// byte for byte (both sides are IEEE-754 doubles).
/// * **Exponent form** — Rust's `{:e}` is shortest-round-trip too (`"1e16"`,
/// `"9.99e-5"`); reformatted to Python's spelling: explicit `+`, exponent
/// zero-padded to two digits (`1e+16`, `1e-05`, `1e+100`).
/// * **inf/nan** — `str(float("inf"))` == `"inf"`, `str(float("nan"))` ==
/// `"nan"` (CPython prints NaN unsigned regardless of the sign bit).
///
/// The sign comes from the *bit*, not a `< 0` compare: `str(-0.0)` is
/// `"-0.0"`, which is why LO renders the negword for negative zero.
/// `str(number)` for the value the dispatcher handed over: `repr(float)` via
/// [`py_float_str`], `str(Decimal)` via the spec port in `strnum` — which
/// keeps trailing zeros (`"1.10"`, leading zeros of `"0.001"` included) and
/// exponent forms (`"1E+2"`), byte for byte.
/// `int(token)` on a run of decimal digits. Python only ever hands a non-digit
/// token here through exponent notation (which no corpus row hits and whose LO
/// output is a crash anyway), so a parse failure reproduces the `ValueError`
/// `int()` raises, as [`N2WError::Value`] — never a foreign exception name.
/// `int(digit)` on a single fractional character, matching Python's per-digit
/// `int(digit)` in the `for digit in right` loop.