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
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
//! Port of `lang_HR.py` (Croatian).
//!
//! Shape: **self-contained**. `Num2Word_HR` subclasses `Num2Word_Base` but
//! defines no `high_numwords`/`mid_numwords`/`low_numwords`, so Python never
//! builds `self.cards` and never sets `MAXVAL`. `to_cardinal` is overridden
//! outright and drives `_int2word` over 3-digit chunks. Consequently
//! `cards`/`maxval`/`merge` stay at their trait defaults here, and there is
//! **no overflow check** — the only ceiling is the `SCALE` table (see below),
//! which raises `KeyError` rather than `OverflowError`.
//!
//! `setup()` sets `negword = "minus"` and `pointword = "zarez"`; everything
//! else stays at the `Num2Word_Base.__init__` defaults (notably
//! `is_title = False`, so [`Lang::title`] is a no-op here).
//!
//! Inherited from `Num2Word_Base` (unchanged by HR, so the trait defaults do
//! the right thing):
//! * `to_ordinal_num(value) -> value` → default `Ok(value.to_string())`.
//! Verified against the corpus: `0` → "0", `-1` → "-1". For a
//! float/Decimal the dispatcher `str()`s the returned value, which
//! [`Lang::ordinal_num_float_entry`]'s default echoes (`1e+16` → "1e+16",
//! `Decimal("1E+2")` → "1E+2", `-0.0` → "-0.0" — all corpus-pinned).
//! * `to_year(value, **kwargs) -> self.to_cardinal(value)` → default
//! delegates through `&self`, picking up the `to_cardinal` override
//! below. HR adds no era/century handling at all, so `to_year` is
//! *literally* `to_cardinal`: year `2024` → "dvije tisuće dvadeset
//! četiri" and year `-500` → "minus petsto" (no "prije Krista"/BC
//! suffix). Note the `**kwargs`: Base's signature swallows every keyword
//! unread, so `to_year(5, anything=...)` is just "pet" — see
//! [`LangHr::to_year_kw`] (`Lang::to_year_kw`).
//!
//! # Float/Decimal routing — everything is textual
//!
//! `Num2Word_HR.to_cardinal` starts with `n = str(number).replace(",", ".")`
//! and branches on `"." in n`. That single string test is the whole routing
//! story, and it differs from Base semantics in every direction at once:
//!
//! * A **whole float keeps its ".0" tail**: `str(5.0)` is "5.0", so
//! `to_cardinal(5.0)` is "pet zarez nula nula" (the "0" fractional digit
//! is counted both as a leading zero and by `_int2word(0)` — see
//! [`LangHr::cardinal_float_textual`]), never Base's whole-value "pet".
//! [`Lang::cardinal_float_entry`] is therefore overridden to send *every*
//! float/Decimal through the textual branch, like `lang_cs.rs`.
//! * An **integral Decimal has no point**: `str(Decimal("5"))` is "5", so it
//! takes the `else` arm — `int("5")` → "pet".
//! * A **string form in exponent notation feeds `int()` a non-integer
//! token** and raises `ValueError`: `str(1e16)` is "1e+16" (repr switches
//! to exponent form at 1e16), `str(Decimal("1E+2"))` is "1E+2". Both are
//! corpus-pinned as ValueError for cardinal and year. This is HR's de
//! facto float ceiling, and it is a *ValueError*, unlike the int path's
//! `SCALE` `KeyError`.
//! * `str(-0.0)` is "-0.0", so **negative zero renders the negword**:
//! "minus nula zarez nula nula" (corpus-pinned for float and Decimal
//! alike; the binding smuggles `Decimal("-0.0")` in as an f64 `-0.0`
//! because `BigDecimal` cannot carry the sign of zero).
//!
//! `to_ordinal`, by contrast, opens with `int(number)` — plain truncation
//! toward zero — so floats lose their fraction *before* the table lookup:
//! `to_ordinal(2.5)` == "drugi", `to_ordinal(0.5)` == "nulai",
//! `to_ordinal(-1.5)` == "minus jedani", and `to_ordinal(1e16)` ==
//! "deset bilijardii" (int(1e16) is exact, then cardinal + "i"). No
//! ValueError here: `int(float)` succeeds where `int(str)` failed. See
//! [`Lang::ordinal_float_entry`].
//!
//! # The Infinity quirk (`str_to_number`)
//!
//! `num2words("Infinity", lang="hr")` in Python: `str_to_number` happily
//! returns `Decimal("Infinity")`, then HR's `to_cardinal` does
//! `int("Infinity")` → **ValueError**. The shim, however, maps
//! `ParsedNumber::Inf` to Base's OverflowError before any HR code runs, so
//! the only interception point is [`LangHr::str_to_number`] (`Lang::str_to_number`), which turns the
//! parsed Inf into the exact ValueError `int()` would raise. Corpus-pinned
//! for "Infinity" and "-Infinity" (cardinal). Known cost, documented rather
//! than hidden: `to_ordinal(Decimal("Infinity"))` in Python raises
//! OverflowError (from `int()`, not caught by the `except (ValueError,
//! TypeError)` arm), which this override turns into ValueError too — no
//! corpus row exercises it. NaN is left to the shim, whose ValueError already
//! matches `int("NaN")`'s type.
//!
//! # Grammatical kwargs: `feminine`
//!
//! `to_cardinal(self, number, feminine=False)` is the only HR signature with
//! a grammatical kwarg. It selects `ONES[digit][1]` ("jedna"/"dvije") — but
//! only where a scale word doesn't force it anyway (`SCALE[1]` tisuća is
//! feminine regardless), and it is silently dropped on negatives (quirk 4
//! below). Corpus-pinned: `21` feminine → "dvadeset jedna", `-5` feminine →
//! "minus pet". [`LangHr::to_cardinal_kw`] / [`LangHr::to_cardinal_float_kw`]
//! (`Lang::to_cardinal_kw` / `Lang::to_cardinal_float_kw`) accept exactly
//! `feminine` (bool or None; anything else falls back to Python).
//!
//! # Faithfully reproduced Python oddities
//!
//! This is a port, not a rewrite. The following all look wrong but are exactly
//! what Python emits, verified against the interpreter and the frozen corpus:
//!
//! 1. **`to_ordinal` is a lookup table plus a naive `+ "i"` fallback.** Python
//! only tables 1..=20, the round tens 30..=90, 100 and 1000. *Every other*
//! input falls through to `self.to_cardinal(num) + "i"`, glueing an "i"
//! onto the last cardinal word with no grammar whatsoever. Hence the
//! corpus rows `to_ordinal(0)` == "nulai", `to_ordinal(42)` ==
//! "četrdeset dvai", `to_ordinal(200)` == "dvjestoi",
//! `to_ordinal(2000)` == "dvije tisućei", `to_ordinal(10000)` ==
//! "deset tisućai" and `to_ordinal(10**10)` == "deset milijardii" (note the
//! doubled "ii" — "milijardi" + "i"). The Python source calls this "a
//! simplified implementation". None of it is corrected here.
//! 2. **`to_ordinal` of a negative works and produces nonsense.** Unlike most
//! modules HR never calls `verify_ordinal`, so no `TypeError` is raised for
//! negatives: `to_ordinal(-1)` == "minus jedani". Preserved.
//! 3. **`SCALE[5]` is "bilijardu"**, an accusative form where every other
//! entry is nominative ("bilijarda" would be the pattern-consistent word).
//! The corpus confirms `to_cardinal(10**15)` == "bilijardu". Kept verbatim.
//! 4. **`_int2word` drops `feminine` when recursing on a negative** — Python's
//! `self._int2word(abs(number))` omits the argument, so the flag silently
//! resets to `False`. Unobservable in the four in-scope modes (which never
//! pass `feminine=True`), but reproduced anyway. See [`LangHr::int2word`].
//! 5. **The `HUNDREDS` word for 600 is "šesto"**, which is also what
//! `ONES[6]` + "o" would spell. That is genuinely the Croatian word; noted
//! only because it makes 675 read "šesto sedamdeset pet".
//!
//! # The SCALE ceiling — a `KeyError`, not an `OverflowError`
//!
//! `SCALE` is keyed 0..=10, i.e. chunk indices up to 1000^10 == 10^30
//! ("kvintilijun"). `_int2word` indexes it with the chunk index for **every**
//! non-zero chunk, so a value needing a 12th chunk — that is, any
//! `abs(n) >= 10**33` — raises `KeyError` with the missing chunk index as the
//! key. This is Croatian's de facto (and rather abrupt) MAXVAL.
//!
//! The leading chunk of a Python `int` is never zero, so the guard
//! `if chunk_len > 0 and chunk != 0` never spares it: the crash is
//! unconditional above the ceiling. Verified against the interpreter:
//! * `to_cardinal(10**33 - 1)` → "devetsto devedeset devet kvintilijuna …" (ok)
//! * `to_cardinal(10**33)` → `KeyError: 11`
//! * `to_cardinal(10**36)` → `KeyError: 12`
//! [`scale`] returns `None` past the table and each call site converts that to
//! [`N2WError::Key`] carrying the same key, matching both the type and the
//! payload.
//!
//! # Currency
//!
//! `Num2Word_HR` carries its own `CURRENCY_FORMS` — HRK, EUR, USD and nothing
//! else — so it is untouched by the `lang_EUR.py` class-dict mutation that
//! `Num2Word_EN.__init__` performs (verified live: HR's dict `is not` EN's).
//! Every other code therefore raises `NotImplementedError`, which the corpus
//! pins for GBP/JPY/KWD/BHD/INR/CNY/CHF.
//!
//! It overrides `to_currency` and `_cents_verbose`; `to_cheque`,
//! `_money_verbose` and `_cents_terse` stay `Num2Word_Base`'s. It defines
//! neither `CURRENCY_ADJECTIVES` nor `CURRENCY_PRECISION`, so both remain
//! Base's empty dicts and [`Lang::currency_precision`] keeps its default 100
//! for every code.
//!
//! See [`build_currency_forms`] for why each form tuple's trailing gender flag
//! is carried as the *string* `"False"`/`"True"` rather than a `bool`.
//!
//! # Faithfully reproduced Python oddities (currency)
//!
//! 6. **`to_cheque` prints the gender flag as the currency name.**
//! `Num2Word_Base.to_cheque` does `cr1, _cr2 = self.CURRENCY_FORMS[currency]`
//! then `unit = cr1[-1] if isinstance(cr1, tuple) else cr1`, intending "the
//! plural form". HR's `cr1` is a **4-tuple**, so `cr1[-1]` is the trailing
//! `bool`, which `"%s"` renders as `False`/`True` and `.upper()` then
//! shouts. The corpus pins it:
//! `to_cheque(1234.56, "EUR")` ==
//! "TISUĆA DVJESTO TRIDESET ČETIRI AND 56/100 FALSE". HRK, whose flag is
//! `True`, would end in "TRUE". Reproduced through the *unmodified*
//! [`crate::currency::default_to_cheque`].
//! 7. **`to_currency` accepts `adjective=` and then ignores it.** The parameter
//! is in HR's signature but its body never reads it — unlike
//! `Num2Word_Base.to_currency`, which would apply `prefix_currency`. So
//! `to_currency(12.34, "EUR", adjective=True)` == the plain
//! "dvanaest eura, trideset četiri centa" (verified live). Moot in practice
//! since `CURRENCY_ADJECTIVES` is empty anyway, but the parameter is dropped
//! here rather than wired to [`Lang::currency_adjective`].
//! 8. **`to_currency` never consults `CURRENCY_PRECISION`.** It calls
//! `parse_currency_parts` without a `divisor=`, taking that function's
//! default of 100, and hardcodes `(decimal_val * 100) % 1` for its
//! fractional-cents test. HR's table is empty so the two agree today, but
//! the 100 below is Python's literal, not `self.currency_precision(...)`:
//! adding a 3-decimal code to `CURRENCY_FORMS` would *not* make it a
//! 3-decimal currency here. Consequently the `divisor == 1` (JPY/KRW)
//! rounding shortcut in `Num2Word_Base.to_currency` has no counterpart at
//! all — HR never reaches that code.
//! 9. **HR's `is_float` is not Base's `has_decimal` guard.** Base decides
//! whether to print cents with `isinstance(val, float) or "." in str(val)`;
//! HR instead uses `not isinstance(val, int)`, fixed at the top of the
//! function. The two disagree on `Decimal("5")`, which HR renders as
//! "pet eura, nula centi" where Base would say "pet eura" (verified live).
//! So [`CurrencyValue`]'s `has_decimal` field is deliberately **unread**
//! here — the `Int` vs `Decimal` variant is the whole test.
//! 10. **The `separator=""` default is falsy, and means a comma.** HR's
//! signature says `separator=""`, then its body does
//! `sep = separator if separator else ","`. So an omitted separator — and an
//! explicitly empty one — both produce ", ", while a real one is used as
//! given: `separator=" i"` yields "dvanaest eura i trideset četiri centa"
//! (verified live). The generated [`Lang::default_separator`] below returns
//! `""` because that is the literal in the signature; the falsy-to-comma
//! step happens inside [`LangHr::to_currency`], as it does in Python.
//!
//! # Scope: fractional cents
//!
//! Reached when `(value * 100) % 1 != 0`, i.e. the value carries more than two
//! decimal places, which makes `parse_currency_parts` hand back a `Decimal`
//! rather than an `int` for the cents.
//!
//! * HR's branch is `self.to_cardinal_float(float(right))` — it names
//! `to_cardinal_float`, so it lands on `Num2Word_Base`'s digit-by-digit float
//! renderer directly, **not** on `Num2Word_HR.to_cardinal`'s own float branch
//! (HR defines no method called `to_cardinal_float`; its float grammar lives
//! *inside* `to_cardinal`).
//! * The Rust `Lang::to_cardinal_float` hook, however, now carries HR's
//! textual grammar (it backs [`Lang::cardinal_float_entry`]), and the trait
//! default of `cardinal_from_decimal` dispatches virtually through it. The
//! two grammars agree on single-digit fractions ("zarez pet") but diverge on
//! multi-digit ones: 65.35 cents is Base's "šezdeset pet zarez tri pet"
//! (digit by digit) vs the textual "… zarez trideset pet" (one integer).
//! [`LangHr::cardinal_from_decimal`] (`Lang::cardinal_from_decimal`)
//! therefore pins the Base grammar explicitly — f64-cast, repr-derived
//! precision, `floatpath::default_to_cardinal_float` — exactly the method
//! Python resolves.
//!
//! Verified against the live interpreter — `to_currency(0.001, "EUR")` ==
//! "nula eura, nula zarez jedan centi" and `to_currency(12.345, "EUR")` ==
//! "dvanaest eura, trideset četiri zarez pet centi". (Contrast `lang_SR`,
//! whose sibling code reaches `self.to_cardinal` and therefore *does* diverge
//! under the same trait default.)
//!
//! The terse half of that corner — `cents=False` **and** fractional cents,
//! where Python emits `str(float(right))` — is handled by [`repr_float`], which
//! documents the one place Rust's float formatting differs from CPython's and
//! why the difference is closable here.
//!
//! # Verification
//!
//! All 117 `hr` currency + cheque corpus rows match byte for byte. Beyond the
//! corpus, ~20k differential cases were run against the live interpreter —
//! every code (including **HRK**, which the corpus never exercises, and unknown
//! codes), `cents=True`/`False`, `separator` omitted/`""`/`" i"`/`","`, `int` /
//! `float` / `Decimal` inputs, negatives, exact powers of ten, the 11..=14
//! paucal boundaries, and fractional cents — with zero mismatches.
//!
//! The float/Decimal, string and kwargs behaviour above was additionally
//! checked against the live interpreter: whole floats ("pet zarez nula
//! nula"), `Decimal("5.00")`'s three nulas, the 1e16 / `1E+2` ValueErrors
//! (message included), ordinal truncation (2.5 → "drugi", 1e16 → "deset
//! bilijardii"), `Decimal("-0.0")` / `Decimal("-0")`, `feminine` threading
//! into both halves of "dvadeset jedna zarez dvadeset jedna", `to_year`'s
//! kwargs swallow, `int("Infinity")`'s exact ValueError text, and
//! `to_currency(0.6535)`'s digit-by-digit "šezdeset pet zarez tri pet centi".
use crate;
use crate;
use crateFloatValue;
use crate;
use BigDecimal;
use BigInt;
use Integer;
use ;
use HashMap;
/// `ZERO[0]`.
const ZERO: &str = "nula";
/// `setup(): self.negword = "minus"`.
const NEGWORD: &str = "minus";
/// `setup(): self.pointword = "zarez"`.
const POINTWORD: &str = "zarez";
/// `ONES`, keys 1..=9, `(masculine, feminine)`. Index 0 is absent in Python
/// (guarded by `digit_right > 0`).
const ONES: = ;
/// `TENS`, keys 0..=9 — the 10..=19 teens, keyed by the *units* digit.
const TENS: = ;
/// `TWENTIES`, keys 2..=9. Indices 0/1 are absent in Python (guarded by
/// `digit_mid > 1`, with `digit_mid == 1` handled by [`TENS`] instead).
const TWENTIES: = ;
/// `HUNDREDS`, keys 1..=9. Index 0 is absent in Python (guarded by
/// `digit_left > 0`).
const HUNDREDS: = ;
/// `SCALE`: chunk index → `(singular, paucal, plural, is_feminine)`.
///
/// Keys 0..=10 only — see the module docs on the `KeyError` ceiling. Index 5
/// is "bilijardu" in the Python source; that typo is load-bearing for parity.
const SCALE: = ;
/// Python's `SCALE[idx]`. `None` models the `KeyError` the dict raises past
/// key 10; callers turn it into [`N2WError::Key`] with `idx` as the key, which
/// is what CPython puts in the exception (`KeyError: 11`).
/// `to_ordinal`'s inline `ordinals` dict. Insertion order is irrelevant — it
/// is only ever probed with `in` / `[]`.
const ORDINALS: = ;
/// Python's `num in ordinals` / `ordinals[num]`.
///
/// A linear scan over 29 entries rather than a `to_u32` narrowing: the table
/// is tiny, and comparing `BigInt`s directly keeps the lookup total for the
/// unbounded inputs this crate must accept (`10**606` must miss, not panic).
/// Python's `"%03d" % n` for the non-negative values this module produces.
///
/// `_int2word` strips the sign before stringifying, and `splitbyx(_, 3)` only
/// ever yields chunks in 0..=999, so the sign-aware branch of `%03d` is
/// unreachable and the result is always exactly 3 chars.
/// Port of `utils.splitbyx(n, x)` with `format_int=True`.
///
/// Infallible here: `_int2word` only ever passes `str(abs(int))`, i.e. a
/// non-empty `[0-9]+` string, so every slice parses. (Contrast `lang_PL`,
/// where a stray "-" reaches this function and raises `ValueError`.)
/// Port of `utils.get_digits(n)`. Returns `[right, mid, left]` — least
/// significant first, matching the `reversed(...)` in Python.
/// The form *index* `Num2Word_HR.pluralize` selects — 0 (singular), 1 (paucal)
/// or 2 (plural).
///
/// Factored out of [`pluralize`] because Python has exactly one duck-typed
/// `pluralize` that indexes whatever sequence it is handed, while the two Rust
/// call sites carry different form shapes: the `SCALE` 4-tuple in
/// [`LangHr::int2word`], and `CurrencyForms`' `Vec<String>` in
/// [`LangHr::pluralize`]. Keeping the *rule* in one place keeps them from
/// drifting apart.
///
/// `number` is non-negative at every call site — `_int2word` strips the sign
/// before chunking, and `to_currency` only ever passes `abs()`-ed parts — so
/// Python's floor-`%` and Rust's `%` would agree; `mod_floor` is used
/// regardless to keep the Python semantics explicit.
/// Port of `Num2Word_HR.pluralize` over a [`SCALE`] entry.
/// `Num2Word_HR.CURRENCY_FORMS`, verbatim — HRK, EUR, USD and nothing else.
///
/// # Why the gender flag is a `"False"`/`"True"` string
///
/// Python's entries are pairs of **4-tuples**: `("euro", "eura", "eura",
/// False)`. That trailing element is a `bool`, and two callers read it wanting
/// two different things:
///
/// * `Num2Word_HR._cents_verbose` reads `CURRENCY_FORMS[cur][1][-1]` and passes
/// it as `_int2word`'s `feminine` argument — its intended purpose.
/// * `Num2Word_Base.to_cheque` reads `cr1[-1]` believing it is the plural unit
/// name and interpolates it into a `"%s"` — module-doc quirk 6. Python
/// renders the bool as the text `False`/`True`, which `.upper()` shouts.
///
/// `CurrencyForms` stores `Vec<String>`, so keeping the flag as the exact text
/// Python's `"%s"` produces reproduces the cheque bug through the *unmodified*
/// [`crate::currency::default_to_cheque`] (which takes `forms.unit.last()`),
/// while [`LangHr::cents_verbose`] recovers the boolean by comparing against
/// `"True"`. Storing a real `bool` would need a parallel table *and* a
/// `to_cheque` override to reprint it — more code, same bytes. This mirrors
/// what `lang_sr.rs` does with the identical Python shape.
///
/// The arity is load-bearing beyond that: [`LangHr::pluralize`] indexes 0..=2,
/// so dropping the third form would silently change output.
/// Python's `str(float(x))` for the terse fractional-cents corner.
///
/// # This is not a general `repr(float)` — it is correct only on `[0, 100)`
///
/// `currency.rs`'s module docs are explicit that re-deriving Python's float
/// formatting in Rust is a permanent source of drift, and they are right about
/// the general case. This is deliberately *not* that: the shortest-round-trip
/// digits still come from Rust's own formatter, which shares CPython `repr`'s
/// contract. Only two mechanical differences are patched, and only over a
/// domain small enough to test exhaustively:
///
/// 1. **The exponent-notation threshold.** CPython's `repr` switches to
/// scientific below `1e-4` (`repr(1e-05) == "1e-05"`, `repr(1e-4) ==
/// "0.0001"`); Rust's `{}` never does. Rust's `{:e}` always does, so the
/// branch picks the right one and reuses `{:e}`'s mantissa as-is.
/// 2. **Exponent zero-padding.** CPython pads to two digits (`1e-05`); Rust's
/// `{:e}` does not (`1e-5`).
///
/// The other half of `repr`'s rule — switching back to scientific at `>= 1e16`
/// — is **not** implemented, because it is unreachable: the only caller passes
/// `right`, the subunit count, which is `fraction * 100` for `fraction` in
/// `[0, 1)`, hence finite, non-negative and `< 100`. Do not reuse this function
/// outside that domain.
///
/// Verified against CPython over 160,965 values spanning exactly that range —
/// uniform draws over `[0, 100)` and over `[0, 1e-4)`, every power of ten down
/// to `1e-319`, subnormals, and the `1e-4` boundary itself — with zero
/// mismatches.
///
/// The `.0` fixup covers the third difference (`repr(34.0)` is `"34.0"` where
/// `format!("{}", 34.0)` is `"34"`). `right` is provably non-integral whenever
/// this runs (see [`LangHr::to_currency`]), but `to_f64` can round a value like
/// `34.000000000000000001` onto an integral double, so the fixup is not dead.
/// Reproduce CPython's `repr(float)` (== `str(float)`) for an `f64`.
///
/// `Num2Word_HR.to_cardinal` starts with `n = str(number)` and then *string-
/// splits* on `.` — it never calls `float2tuple`, so the f64-artefact heuristic
/// in `floatpath` is irrelevant here: the port must rebuild the exact repr
/// string, exponent form included (`str(1e16)` is "1e+16", which is what makes
/// HR raise ValueError above 1e16 — see [`LangHr::cardinal_float_textual`]).
///
/// CPython uses David Gay's shortest `dtoa` (mode 0): a digit string plus a
/// decimal-point position `decpt`. It then prints fixed notation iff
/// `-4 < decpt <= 16` and scientific otherwise, appending `.0` in fixed
/// notation when nothing follows the point (`Py_DTSF_ADD_DOT_0`) and padding
/// the scientific exponent to at least two digits (`1e-05`, `1e+16`). Rust's
/// `{:e}` emits the same shortest digit string with `decpt == exp + 1`, so the
/// two reconstruct identically. Same helper as `lang_cs.rs` (whose Python
/// original shares HR's textual `to_cardinal` shape), duplicated because
/// language modules do not import from one another.
/// Python's `int(token)` for the tokens `Num2Word_HR.to_cardinal` feeds it:
/// `int(left)`, `int(right)` (unsigned — the sign is stripped before the
/// split) and `int(n)` in the else arm (signed — `str(Decimal("-3"))` is
/// "-3", and `_int2word` does its own negative handling).
///
/// A token with any non-digit — the `'e'`/`'E'`/`'+'` of an exponent-form
/// repr ("1e+16", "1E+2"), `'inf'`, `'nan'`, `'Infinity'` — is where Python's
/// `int()` raises `ValueError`, which the HR float path never guards. Same
/// exception type, same message format string.
/// `abs(Decimal(repr(f)).as_tuple().exponent)` for an f64 — the repr-derived
/// precision Base's `float2tuple` assigns. Local copy of `floatpath`'s
/// private helper, used only by [`LangHr::cardinal_from_decimal`].
/// Extract the `feminine=` kwarg the way `Num2Word_HR.to_cardinal` consumes
/// it.
///
/// * omitted → the signature default `False`;
/// * an explicit `None` → falsy, so `None or SCALE[i][-1]` behaves exactly
/// like `False` — `int(None)` is never reached;
/// * a bool → itself (the only shape the kwargs corpus exercises);
/// * anything else (`feminine=2`, a string, …) → NotImplemented, so the
/// dispatcher falls back to Python, which reproduces its own outcome
/// (`gender_idx = int(is_feminine)` then `ONES[d][gender_idx]` —
/// IndexError for 2, TypeError for a non-int, truthiness for 1).