@cj-tech-master/excelts 9.3.1 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/browser/index.d.ts +1 -0
  2. package/dist/browser/index.js +2 -0
  3. package/dist/browser/modules/excel/cell.d.ts +18 -0
  4. package/dist/browser/modules/excel/cell.js +21 -0
  5. package/dist/browser/modules/excel/utils/cell-format.js +85 -13
  6. package/dist/browser/modules/excel/workbook.browser.d.ts +57 -0
  7. package/dist/browser/modules/excel/workbook.browser.js +49 -0
  8. package/dist/browser/modules/excel/xlsx/defaultnumformats.js +3 -3
  9. package/dist/browser/modules/formula/compile/binder.js +48 -6
  10. package/dist/browser/modules/formula/compile/bound-ast.d.ts +16 -2
  11. package/dist/browser/modules/formula/compile/bound-ast.js +1 -0
  12. package/dist/browser/modules/formula/compile/compiled-formula.js +41 -8
  13. package/dist/browser/modules/formula/functions/_shared.d.ts +19 -0
  14. package/dist/browser/modules/formula/functions/_shared.js +47 -0
  15. package/dist/browser/modules/formula/functions/conditional.js +103 -22
  16. package/dist/browser/modules/formula/functions/date.js +105 -23
  17. package/dist/browser/modules/formula/functions/dynamic-array.js +173 -69
  18. package/dist/browser/modules/formula/functions/engineering.d.ts +2 -2
  19. package/dist/browser/modules/formula/functions/engineering.js +103 -151
  20. package/dist/browser/modules/formula/functions/financial.js +210 -184
  21. package/dist/browser/modules/formula/functions/lookup.js +224 -157
  22. package/dist/browser/modules/formula/functions/math.d.ts +26 -0
  23. package/dist/browser/modules/formula/functions/math.js +249 -69
  24. package/dist/browser/modules/formula/functions/statistical.js +221 -171
  25. package/dist/browser/modules/formula/functions/text.js +112 -52
  26. package/dist/browser/modules/formula/integration/calculate-formulas-impl.js +20 -1
  27. package/dist/browser/modules/formula/materialize/build-writeback-plan.js +10 -6
  28. package/dist/browser/modules/formula/materialize/types.d.ts +15 -0
  29. package/dist/browser/modules/formula/runtime/evaluator.d.ts +8 -0
  30. package/dist/browser/modules/formula/runtime/evaluator.js +582 -162
  31. package/dist/browser/modules/formula/runtime/function-registry.d.ts +5 -0
  32. package/dist/browser/modules/formula/runtime/function-registry.js +59 -13
  33. package/dist/browser/modules/formula/runtime/values.d.ts +13 -0
  34. package/dist/browser/modules/formula/runtime/values.js +20 -2
  35. package/dist/browser/modules/formula/syntax/ast.d.ts +14 -2
  36. package/dist/browser/modules/formula/syntax/ast.js +1 -0
  37. package/dist/browser/modules/formula/syntax/parser.js +29 -7
  38. package/dist/browser/modules/formula/syntax/token-types.d.ts +4 -0
  39. package/dist/browser/modules/formula/syntax/token-types.js +9 -0
  40. package/dist/browser/modules/formula/syntax/tokenizer.js +76 -19
  41. package/dist/cjs/index.js +7 -2
  42. package/dist/cjs/modules/excel/cell.js +21 -0
  43. package/dist/cjs/modules/excel/utils/cell-format.js +85 -13
  44. package/dist/cjs/modules/excel/workbook.browser.js +49 -0
  45. package/dist/cjs/modules/excel/xlsx/defaultnumformats.js +3 -3
  46. package/dist/cjs/modules/formula/compile/binder.js +48 -6
  47. package/dist/cjs/modules/formula/compile/compiled-formula.js +41 -8
  48. package/dist/cjs/modules/formula/functions/_shared.js +48 -0
  49. package/dist/cjs/modules/formula/functions/conditional.js +103 -22
  50. package/dist/cjs/modules/formula/functions/date.js +104 -22
  51. package/dist/cjs/modules/formula/functions/dynamic-array.js +173 -69
  52. package/dist/cjs/modules/formula/functions/engineering.js +109 -157
  53. package/dist/cjs/modules/formula/functions/financial.js +209 -183
  54. package/dist/cjs/modules/formula/functions/lookup.js +224 -157
  55. package/dist/cjs/modules/formula/functions/math.js +254 -70
  56. package/dist/cjs/modules/formula/functions/statistical.js +222 -172
  57. package/dist/cjs/modules/formula/functions/text.js +112 -52
  58. package/dist/cjs/modules/formula/integration/calculate-formulas-impl.js +20 -1
  59. package/dist/cjs/modules/formula/materialize/build-writeback-plan.js +10 -6
  60. package/dist/cjs/modules/formula/runtime/evaluator.js +581 -161
  61. package/dist/cjs/modules/formula/runtime/function-registry.js +57 -11
  62. package/dist/cjs/modules/formula/runtime/values.js +21 -2
  63. package/dist/cjs/modules/formula/syntax/parser.js +29 -7
  64. package/dist/cjs/modules/formula/syntax/token-types.js +9 -0
  65. package/dist/cjs/modules/formula/syntax/tokenizer.js +76 -19
  66. package/dist/esm/index.js +2 -0
  67. package/dist/esm/modules/excel/cell.js +21 -0
  68. package/dist/esm/modules/excel/utils/cell-format.js +85 -13
  69. package/dist/esm/modules/excel/workbook.browser.js +49 -0
  70. package/dist/esm/modules/excel/xlsx/defaultnumformats.js +3 -3
  71. package/dist/esm/modules/formula/compile/binder.js +48 -6
  72. package/dist/esm/modules/formula/compile/bound-ast.js +1 -0
  73. package/dist/esm/modules/formula/compile/compiled-formula.js +41 -8
  74. package/dist/esm/modules/formula/functions/_shared.js +47 -0
  75. package/dist/esm/modules/formula/functions/conditional.js +103 -22
  76. package/dist/esm/modules/formula/functions/date.js +105 -23
  77. package/dist/esm/modules/formula/functions/dynamic-array.js +173 -69
  78. package/dist/esm/modules/formula/functions/engineering.js +103 -151
  79. package/dist/esm/modules/formula/functions/financial.js +210 -184
  80. package/dist/esm/modules/formula/functions/lookup.js +224 -157
  81. package/dist/esm/modules/formula/functions/math.js +249 -69
  82. package/dist/esm/modules/formula/functions/statistical.js +221 -171
  83. package/dist/esm/modules/formula/functions/text.js +112 -52
  84. package/dist/esm/modules/formula/integration/calculate-formulas-impl.js +20 -1
  85. package/dist/esm/modules/formula/materialize/build-writeback-plan.js +10 -6
  86. package/dist/esm/modules/formula/runtime/evaluator.js +582 -162
  87. package/dist/esm/modules/formula/runtime/function-registry.js +59 -13
  88. package/dist/esm/modules/formula/runtime/values.js +20 -2
  89. package/dist/esm/modules/formula/syntax/ast.js +1 -0
  90. package/dist/esm/modules/formula/syntax/parser.js +29 -7
  91. package/dist/esm/modules/formula/syntax/token-types.js +9 -0
  92. package/dist/esm/modules/formula/syntax/tokenizer.js +76 -19
  93. package/dist/iife/excelts.iife.js +1502 -1379
  94. package/dist/iife/excelts.iife.js.map +1 -1
  95. package/dist/iife/excelts.iife.min.js +26 -26
  96. package/dist/types/index.d.ts +1 -0
  97. package/dist/types/modules/excel/cell.d.ts +18 -0
  98. package/dist/types/modules/excel/workbook.browser.d.ts +57 -0
  99. package/dist/types/modules/formula/compile/bound-ast.d.ts +16 -2
  100. package/dist/types/modules/formula/functions/_shared.d.ts +19 -0
  101. package/dist/types/modules/formula/functions/engineering.d.ts +2 -2
  102. package/dist/types/modules/formula/functions/math.d.ts +26 -0
  103. package/dist/types/modules/formula/materialize/types.d.ts +15 -0
  104. package/dist/types/modules/formula/runtime/evaluator.d.ts +8 -0
  105. package/dist/types/modules/formula/runtime/function-registry.d.ts +5 -0
  106. package/dist/types/modules/formula/runtime/values.d.ts +13 -0
  107. package/dist/types/modules/formula/syntax/ast.d.ts +14 -2
  108. package/dist/types/modules/formula/syntax/token-types.d.ts +4 -0
  109. package/package.json +1 -1
@@ -23,23 +23,23 @@ function toDate(serial) {
23
23
  // Financial Functions
24
24
  // ============================================================================
25
25
  const fnPMT = args => {
26
- const rate = (0, values_1.toNumberRV)(args[0]);
26
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
27
27
  if ((0, values_1.isError)(rate)) {
28
28
  return rate;
29
29
  }
30
- const nper = (0, values_1.toNumberRV)(args[1]);
30
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
31
31
  if ((0, values_1.isError)(nper)) {
32
32
  return nper;
33
33
  }
34
- const pv = (0, values_1.toNumberRV)(args[2]);
34
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
35
35
  if ((0, values_1.isError)(pv)) {
36
36
  return pv;
37
37
  }
38
- const fv = args.length > 3 ? (0, values_1.toNumberRV)(args[3]) : (0, values_1.rvNumber)(0);
38
+ const fv = args.length > 3 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3])) : (0, values_1.rvNumber)(0);
39
39
  if ((0, values_1.isError)(fv)) {
40
40
  return fv;
41
41
  }
42
- const type = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
42
+ const type = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
43
43
  if ((0, values_1.isError)(type)) {
44
44
  return type;
45
45
  }
@@ -66,23 +66,23 @@ const fnPMT = args => {
66
66
  };
67
67
  exports.fnPMT = fnPMT;
68
68
  const fnFV = args => {
69
- const rate = (0, values_1.toNumberRV)(args[0]);
69
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
70
70
  if ((0, values_1.isError)(rate)) {
71
71
  return rate;
72
72
  }
73
- const nper = (0, values_1.toNumberRV)(args[1]);
73
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
74
74
  if ((0, values_1.isError)(nper)) {
75
75
  return nper;
76
76
  }
77
- const pmt = (0, values_1.toNumberRV)(args[2]);
77
+ const pmt = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
78
78
  if ((0, values_1.isError)(pmt)) {
79
79
  return pmt;
80
80
  }
81
- const pv = args.length > 3 ? (0, values_1.toNumberRV)(args[3]) : (0, values_1.rvNumber)(0);
81
+ const pv = args.length > 3 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3])) : (0, values_1.rvNumber)(0);
82
82
  if ((0, values_1.isError)(pv)) {
83
83
  return pv;
84
84
  }
85
- const type = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
85
+ const type = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
86
86
  if ((0, values_1.isError)(type)) {
87
87
  return type;
88
88
  }
@@ -102,23 +102,23 @@ const fnFV = args => {
102
102
  };
103
103
  exports.fnFV = fnFV;
104
104
  const fnPV = args => {
105
- const rate = (0, values_1.toNumberRV)(args[0]);
105
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
106
106
  if ((0, values_1.isError)(rate)) {
107
107
  return rate;
108
108
  }
109
- const nper = (0, values_1.toNumberRV)(args[1]);
109
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
110
110
  if ((0, values_1.isError)(nper)) {
111
111
  return nper;
112
112
  }
113
- const pmt = (0, values_1.toNumberRV)(args[2]);
113
+ const pmt = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
114
114
  if ((0, values_1.isError)(pmt)) {
115
115
  return pmt;
116
116
  }
117
- const fv = args.length > 3 ? (0, values_1.toNumberRV)(args[3]) : (0, values_1.rvNumber)(0);
117
+ const fv = args.length > 3 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3])) : (0, values_1.rvNumber)(0);
118
118
  if ((0, values_1.isError)(fv)) {
119
119
  return fv;
120
120
  }
121
- const type = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
121
+ const type = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
122
122
  if ((0, values_1.isError)(type)) {
123
123
  return type;
124
124
  }
@@ -137,7 +137,7 @@ const fnPV = args => {
137
137
  };
138
138
  exports.fnPV = fnPV;
139
139
  const fnNPV = args => {
140
- const rate = (0, values_1.toNumberRV)(args[0]);
140
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
141
141
  if ((0, values_1.isError)(rate)) {
142
142
  return rate;
143
143
  }
@@ -154,6 +154,12 @@ const fnNPV = args => {
154
154
  if ((0, values_1.isArray)(a)) {
155
155
  for (const row of a.rows) {
156
156
  for (const cell of row) {
157
+ // Propagate errors encountered inside the cash-flow range —
158
+ // previously silently filtered, hiding `#N/A` / `#DIV/0!`
159
+ // that should surface as the NPV result.
160
+ if (cell.kind === 4 /* RVKind.Error */) {
161
+ return cell;
162
+ }
157
163
  if (cell.kind === 1 /* RVKind.Number */) {
158
164
  values.push(cell.value);
159
165
  }
@@ -213,7 +219,13 @@ const fnIRR = args => {
213
219
  if (!hasPos || !hasNeg) {
214
220
  return values_1.ERRORS.NUM;
215
221
  }
216
- const guessRV = args.length > 1 ? (0, values_1.toNumberRV)(args[1]) : (0, values_1.rvNumber)(0.1);
222
+ // Excel's `guess` argument defaults to 0.1 when omitted. A user-supplied
223
+ // BLANK (e.g. `IRR(B2:B6, )` with an empty second slot) should also fall
224
+ // back to 0.1 — without this the Newton scan starts at `g = 0`, which
225
+ // sits exactly at the discount-factor singularity of several cash-flow
226
+ // shapes and can fail to converge. Genuine numeric guesses (including 0
227
+ // explicitly supplied as a number) are honoured as given.
228
+ const guessRV = args.length > 1 && args[1].kind !== 0 /* RVKind.Blank */ ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1])) : (0, values_1.rvNumber)(0.1);
217
229
  if ((0, values_1.isError)(guessRV)) {
218
230
  return guessRV;
219
231
  }
@@ -291,23 +303,23 @@ const fnIRR = args => {
291
303
  };
292
304
  exports.fnIRR = fnIRR;
293
305
  const fnNPER = args => {
294
- const rate = (0, values_1.toNumberRV)(args[0]);
306
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
295
307
  if ((0, values_1.isError)(rate)) {
296
308
  return rate;
297
309
  }
298
- const pmt = (0, values_1.toNumberRV)(args[1]);
310
+ const pmt = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
299
311
  if ((0, values_1.isError)(pmt)) {
300
312
  return pmt;
301
313
  }
302
- const pv = (0, values_1.toNumberRV)(args[2]);
314
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
303
315
  if ((0, values_1.isError)(pv)) {
304
316
  return pv;
305
317
  }
306
- const fv = args.length > 3 ? (0, values_1.toNumberRV)(args[3]) : (0, values_1.rvNumber)(0);
318
+ const fv = args.length > 3 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3])) : (0, values_1.rvNumber)(0);
307
319
  if ((0, values_1.isError)(fv)) {
308
320
  return fv;
309
321
  }
310
- const type = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
322
+ const type = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
311
323
  if ((0, values_1.isError)(type)) {
312
324
  return type;
313
325
  }
@@ -338,27 +350,30 @@ const fnNPER = args => {
338
350
  };
339
351
  exports.fnNPER = fnNPER;
340
352
  const fnRATE = args => {
341
- const nper = (0, values_1.toNumberRV)(args[0]);
353
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
342
354
  if ((0, values_1.isError)(nper)) {
343
355
  return nper;
344
356
  }
345
- const pmt = (0, values_1.toNumberRV)(args[1]);
357
+ const pmt = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
346
358
  if ((0, values_1.isError)(pmt)) {
347
359
  return pmt;
348
360
  }
349
- const pv = (0, values_1.toNumberRV)(args[2]);
361
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
350
362
  if ((0, values_1.isError)(pv)) {
351
363
  return pv;
352
364
  }
353
- const fv = args.length > 3 ? (0, values_1.toNumberRV)(args[3]) : (0, values_1.rvNumber)(0);
365
+ const fv = args.length > 3 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3])) : (0, values_1.rvNumber)(0);
354
366
  if ((0, values_1.isError)(fv)) {
355
367
  return fv;
356
368
  }
357
- const type = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
369
+ const type = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
358
370
  if ((0, values_1.isError)(type)) {
359
371
  return type;
360
372
  }
361
- const guess = args.length > 5 ? (0, values_1.toNumberRV)(args[5]) : (0, values_1.rvNumber)(0.1);
373
+ // Blank default 0.1 (see IRR / XIRR for rationale). For `fv` and
374
+ // `type` a blank coerces to 0 via `toNumberRV`, which matches Excel's
375
+ // documented defaults, so those are left as-is.
376
+ const guess = args.length > 5 && args[5].kind !== 0 /* RVKind.Blank */ ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5])) : (0, values_1.rvNumber)(0.1);
362
377
  if ((0, values_1.isError)(guess)) {
363
378
  return guess;
364
379
  }
@@ -424,15 +439,15 @@ const fnRATE = args => {
424
439
  };
425
440
  exports.fnRATE = fnRATE;
426
441
  const fnSLN = args => {
427
- const cost = (0, values_1.toNumberRV)(args[0]);
442
+ const cost = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
428
443
  if ((0, values_1.isError)(cost)) {
429
444
  return cost;
430
445
  }
431
- const salvage = (0, values_1.toNumberRV)(args[1]);
446
+ const salvage = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
432
447
  if ((0, values_1.isError)(salvage)) {
433
448
  return salvage;
434
449
  }
435
- const life = (0, values_1.toNumberRV)(args[2]);
450
+ const life = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
436
451
  if ((0, values_1.isError)(life)) {
437
452
  return life;
438
453
  }
@@ -452,19 +467,19 @@ exports.fnSLN = fnSLN;
452
467
  * Excel rejects `life = 0` and period outside [1, life] with #NUM!.
453
468
  */
454
469
  const fnSYD = args => {
455
- const cost = (0, values_1.toNumberRV)(args[0]);
470
+ const cost = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
456
471
  if ((0, values_1.isError)(cost)) {
457
472
  return cost;
458
473
  }
459
- const salvage = (0, values_1.toNumberRV)(args[1]);
474
+ const salvage = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
460
475
  if ((0, values_1.isError)(salvage)) {
461
476
  return salvage;
462
477
  }
463
- const life = (0, values_1.toNumberRV)(args[2]);
478
+ const life = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
464
479
  if ((0, values_1.isError)(life)) {
465
480
  return life;
466
481
  }
467
- const per = (0, values_1.toNumberRV)(args[3]);
482
+ const per = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
468
483
  if ((0, values_1.isError)(per)) {
469
484
  return per;
470
485
  }
@@ -488,31 +503,33 @@ exports.fnSYD = fnSYD;
488
503
  * periods.
489
504
  */
490
505
  const fnVDB = args => {
491
- const cost = (0, values_1.toNumberRV)(args[0]);
506
+ const cost = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
492
507
  if ((0, values_1.isError)(cost)) {
493
508
  return cost;
494
509
  }
495
- const salvage = (0, values_1.toNumberRV)(args[1]);
510
+ const salvage = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
496
511
  if ((0, values_1.isError)(salvage)) {
497
512
  return salvage;
498
513
  }
499
- const life = (0, values_1.toNumberRV)(args[2]);
514
+ const life = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
500
515
  if ((0, values_1.isError)(life)) {
501
516
  return life;
502
517
  }
503
- const start = (0, values_1.toNumberRV)(args[3]);
518
+ const start = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
504
519
  if ((0, values_1.isError)(start)) {
505
520
  return start;
506
521
  }
507
- const end = (0, values_1.toNumberRV)(args[4]);
522
+ const end = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
508
523
  if ((0, values_1.isError)(end)) {
509
524
  return end;
510
525
  }
511
- const factorRV = args.length > 5 ? (0, values_1.toNumberRV)(args[5]) : (0, values_1.rvNumber)(2);
526
+ const factorRV = args.length > 5 && args[5].kind !== 0 /* RVKind.Blank */ ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5])) : (0, values_1.rvNumber)(2);
512
527
  if ((0, values_1.isError)(factorRV)) {
513
528
  return factorRV;
514
529
  }
515
- const noSwitchRV = args.length > 6 ? (0, values_1.toBooleanRV)(args[6]) : (0, values_1.rvBoolean)(false);
530
+ const noSwitchRV = args.length > 6 && args[6].kind !== 0 /* RVKind.Blank */
531
+ ? (0, values_1.toBooleanRV)((0, values_1.topLeft)(args[6]))
532
+ : (0, values_1.rvBoolean)(false);
516
533
  if ((0, values_1.isError)(noSwitchRV)) {
517
534
  return noSwitchRV;
518
535
  }
@@ -577,23 +594,27 @@ const fnVDB = args => {
577
594
  };
578
595
  exports.fnVDB = fnVDB;
579
596
  const fnDB = args => {
580
- const cost = (0, values_1.toNumberRV)(args[0]);
597
+ const cost = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
581
598
  if ((0, values_1.isError)(cost)) {
582
599
  return cost;
583
600
  }
584
- const salvage = (0, values_1.toNumberRV)(args[1]);
601
+ const salvage = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
585
602
  if ((0, values_1.isError)(salvage)) {
586
603
  return salvage;
587
604
  }
588
- const life = (0, values_1.toNumberRV)(args[2]);
605
+ const life = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
589
606
  if ((0, values_1.isError)(life)) {
590
607
  return life;
591
608
  }
592
- const period = (0, values_1.toNumberRV)(args[3]);
609
+ const period = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
593
610
  if ((0, values_1.isError)(period)) {
594
611
  return period;
595
612
  }
596
- const month = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(12);
613
+ // Blank `month` Excel default 12 (full first year). Without the
614
+ // blank guard, `toNumberRV(BLANK)` coerces to 0 which then trips the
615
+ // `month < 1` validation below, silently surfacing #NUM! for
616
+ // `DB(cost, salvage, life, period, )`.
617
+ const month = args.length > 4 && args[4].kind !== 0 /* RVKind.Blank */ ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(12);
597
618
  if ((0, values_1.isError)(month)) {
598
619
  return month;
599
620
  }
@@ -637,23 +658,25 @@ const fnDB = args => {
637
658
  };
638
659
  exports.fnDB = fnDB;
639
660
  const fnDDB = args => {
640
- const cost = (0, values_1.toNumberRV)(args[0]);
661
+ const cost = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
641
662
  if ((0, values_1.isError)(cost)) {
642
663
  return cost;
643
664
  }
644
- const salvage = (0, values_1.toNumberRV)(args[1]);
665
+ const salvage = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
645
666
  if ((0, values_1.isError)(salvage)) {
646
667
  return salvage;
647
668
  }
648
- const life = (0, values_1.toNumberRV)(args[2]);
669
+ const life = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
649
670
  if ((0, values_1.isError)(life)) {
650
671
  return life;
651
672
  }
652
- const period = (0, values_1.toNumberRV)(args[3]);
673
+ const period = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
653
674
  if ((0, values_1.isError)(period)) {
654
675
  return period;
655
676
  }
656
- const factor = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(2);
677
+ // Blank `factor` Excel default 2 (double declining). See DB/IRR for
678
+ // why blank must be distinguished from an explicit 0.
679
+ const factor = args.length > 4 && args[4].kind !== 0 /* RVKind.Blank */ ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(2);
657
680
  if ((0, values_1.isError)(factor)) {
658
681
  return factor;
659
682
  }
@@ -712,27 +735,27 @@ function ipmtRaw(rate, per, nper, pv, fv, type) {
712
735
  return type === 1 ? ipmt / (1 + rate) : ipmt;
713
736
  }
714
737
  const fnIPMT = args => {
715
- const rate = (0, values_1.toNumberRV)(args[0]);
738
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
716
739
  if ((0, values_1.isError)(rate)) {
717
740
  return rate;
718
741
  }
719
- const per = (0, values_1.toNumberRV)(args[1]);
742
+ const per = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
720
743
  if ((0, values_1.isError)(per)) {
721
744
  return per;
722
745
  }
723
- const nper = (0, values_1.toNumberRV)(args[2]);
746
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
724
747
  if ((0, values_1.isError)(nper)) {
725
748
  return nper;
726
749
  }
727
- const pv = (0, values_1.toNumberRV)(args[3]);
750
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
728
751
  if ((0, values_1.isError)(pv)) {
729
752
  return pv;
730
753
  }
731
- const fv = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
754
+ const fv = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
732
755
  if ((0, values_1.isError)(fv)) {
733
756
  return fv;
734
757
  }
735
- const type = args.length > 5 ? (0, values_1.toNumberRV)(args[5]) : (0, values_1.rvNumber)(0);
758
+ const type = args.length > 5 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5])) : (0, values_1.rvNumber)(0);
736
759
  if ((0, values_1.isError)(type)) {
737
760
  return type;
738
761
  }
@@ -740,27 +763,27 @@ const fnIPMT = args => {
740
763
  };
741
764
  exports.fnIPMT = fnIPMT;
742
765
  const fnPPMT = args => {
743
- const rate = (0, values_1.toNumberRV)(args[0]);
766
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
744
767
  if ((0, values_1.isError)(rate)) {
745
768
  return rate;
746
769
  }
747
- const per = (0, values_1.toNumberRV)(args[1]);
770
+ const per = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
748
771
  if ((0, values_1.isError)(per)) {
749
772
  return per;
750
773
  }
751
- const nper = (0, values_1.toNumberRV)(args[2]);
774
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
752
775
  if ((0, values_1.isError)(nper)) {
753
776
  return nper;
754
777
  }
755
- const pv = (0, values_1.toNumberRV)(args[3]);
778
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
756
779
  if ((0, values_1.isError)(pv)) {
757
780
  return pv;
758
781
  }
759
- const fv = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
782
+ const fv = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
760
783
  if ((0, values_1.isError)(fv)) {
761
784
  return fv;
762
785
  }
763
- const type = args.length > 5 ? (0, values_1.toNumberRV)(args[5]) : (0, values_1.rvNumber)(0);
786
+ const type = args.length > 5 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5])) : (0, values_1.rvNumber)(0);
764
787
  if ((0, values_1.isError)(type)) {
765
788
  return type;
766
789
  }
@@ -781,7 +804,7 @@ exports.fnPPMT = fnPPMT;
781
804
  * propagates any error it encounters. Text values produce #VALUE!.
782
805
  */
783
806
  const fnFVSCHEDULE = args => {
784
- const principal = (0, values_1.toNumberRV)(args[0]);
807
+ const principal = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
785
808
  if ((0, values_1.isError)(principal)) {
786
809
  return principal;
787
810
  }
@@ -833,15 +856,15 @@ exports.fnFVSCHEDULE = fnFVSCHEDULE;
833
856
  * Excel requires `rate > 0` and `pv, fv > 0`.
834
857
  */
835
858
  const fnPDURATION = args => {
836
- const rate = (0, values_1.toNumberRV)(args[0]);
859
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
837
860
  if ((0, values_1.isError)(rate)) {
838
861
  return rate;
839
862
  }
840
- const pv = (0, values_1.toNumberRV)(args[1]);
863
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
841
864
  if ((0, values_1.isError)(pv)) {
842
865
  return pv;
843
866
  }
844
- const fv = (0, values_1.toNumberRV)(args[2]);
867
+ const fv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
845
868
  if ((0, values_1.isError)(fv)) {
846
869
  return fv;
847
870
  }
@@ -859,15 +882,15 @@ exports.fnPDURATION = fnPDURATION;
859
882
  * Excel requires `nper > 0`, `pv > 0`, `fv >= 0`.
860
883
  */
861
884
  const fnRRI = args => {
862
- const nper = (0, values_1.toNumberRV)(args[0]);
885
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
863
886
  if ((0, values_1.isError)(nper)) {
864
887
  return nper;
865
888
  }
866
- const pv = (0, values_1.toNumberRV)(args[1]);
889
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
867
890
  if ((0, values_1.isError)(pv)) {
868
891
  return pv;
869
892
  }
870
- const fv = (0, values_1.toNumberRV)(args[2]);
893
+ const fv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
871
894
  if ((0, values_1.isError)(fv)) {
872
895
  return fv;
873
896
  }
@@ -878,11 +901,11 @@ const fnRRI = args => {
878
901
  };
879
902
  exports.fnRRI = fnRRI;
880
903
  const fnEFFECT = args => {
881
- const nomRate = (0, values_1.toNumberRV)(args[0]);
904
+ const nomRate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
882
905
  if ((0, values_1.isError)(nomRate)) {
883
906
  return nomRate;
884
907
  }
885
- const npery = (0, values_1.toNumberRV)(args[1]);
908
+ const npery = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
886
909
  if ((0, values_1.isError)(npery)) {
887
910
  return npery;
888
911
  }
@@ -893,11 +916,11 @@ const fnEFFECT = args => {
893
916
  };
894
917
  exports.fnEFFECT = fnEFFECT;
895
918
  const fnNOMINAL = args => {
896
- const effRate = (0, values_1.toNumberRV)(args[0]);
919
+ const effRate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
897
920
  if ((0, values_1.isError)(effRate)) {
898
921
  return effRate;
899
922
  }
900
- const npery = (0, values_1.toNumberRV)(args[1]);
923
+ const npery = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
901
924
  if ((0, values_1.isError)(npery)) {
902
925
  return npery;
903
926
  }
@@ -909,7 +932,7 @@ const fnNOMINAL = args => {
909
932
  };
910
933
  exports.fnNOMINAL = fnNOMINAL;
911
934
  const fnXNPV = args => {
912
- const rate = (0, values_1.toNumberRV)(args[0]);
935
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
913
936
  if ((0, values_1.isError)(rate)) {
914
937
  return rate;
915
938
  }
@@ -980,7 +1003,8 @@ const fnXIRR = args => {
980
1003
  if (!xHasPos || !xHasNeg) {
981
1004
  return values_1.ERRORS.NUM;
982
1005
  }
983
- const guessRV = args.length > 2 ? (0, values_1.toNumberRV)(args[2]) : (0, values_1.rvNumber)(0.1);
1006
+ // Blank third slot default 0.1, same rationale as IRR above.
1007
+ const guessRV = args.length > 2 && args[2].kind !== 0 /* RVKind.Blank */ ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2])) : (0, values_1.rvNumber)(0.1);
984
1008
  if ((0, values_1.isError)(guessRV)) {
985
1009
  return guessRV;
986
1010
  }
@@ -1067,11 +1091,11 @@ const fnMIRR = args => {
1067
1091
  return valuesErr;
1068
1092
  }
1069
1093
  const values = rawValues.map(n => n.value);
1070
- const financeRate = (0, values_1.toNumberRV)(args[1]);
1094
+ const financeRate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1071
1095
  if ((0, values_1.isError)(financeRate)) {
1072
1096
  return financeRate;
1073
1097
  }
1074
- const reinvestRate = (0, values_1.toNumberRV)(args[2]);
1098
+ const reinvestRate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1075
1099
  if ((0, values_1.isError)(reinvestRate)) {
1076
1100
  return reinvestRate;
1077
1101
  }
@@ -1101,19 +1125,19 @@ const fnMIRR = args => {
1101
1125
  };
1102
1126
  exports.fnMIRR = fnMIRR;
1103
1127
  const fnISPMT = args => {
1104
- const rate = (0, values_1.toNumberRV)(args[0]);
1128
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1105
1129
  if ((0, values_1.isError)(rate)) {
1106
1130
  return rate;
1107
1131
  }
1108
- const per = (0, values_1.toNumberRV)(args[1]);
1132
+ const per = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1109
1133
  if ((0, values_1.isError)(per)) {
1110
1134
  return per;
1111
1135
  }
1112
- const nper = (0, values_1.toNumberRV)(args[2]);
1136
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1113
1137
  if ((0, values_1.isError)(nper)) {
1114
1138
  return nper;
1115
1139
  }
1116
- const pv = (0, values_1.toNumberRV)(args[3]);
1140
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1117
1141
  if ((0, values_1.isError)(pv)) {
1118
1142
  return pv;
1119
1143
  }
@@ -1126,27 +1150,27 @@ const fnISPMT = args => {
1126
1150
  };
1127
1151
  exports.fnISPMT = fnISPMT;
1128
1152
  const fnCUMPRINC = args => {
1129
- const rate = (0, values_1.toNumberRV)(args[0]);
1153
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1130
1154
  if ((0, values_1.isError)(rate)) {
1131
1155
  return rate;
1132
1156
  }
1133
- const nper = (0, values_1.toNumberRV)(args[1]);
1157
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1134
1158
  if ((0, values_1.isError)(nper)) {
1135
1159
  return nper;
1136
1160
  }
1137
- const pv = (0, values_1.toNumberRV)(args[2]);
1161
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1138
1162
  if ((0, values_1.isError)(pv)) {
1139
1163
  return pv;
1140
1164
  }
1141
- const startPeriod = (0, values_1.toNumberRV)(args[3]);
1165
+ const startPeriod = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1142
1166
  if ((0, values_1.isError)(startPeriod)) {
1143
1167
  return startPeriod;
1144
1168
  }
1145
- const endPeriod = (0, values_1.toNumberRV)(args[4]);
1169
+ const endPeriod = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
1146
1170
  if ((0, values_1.isError)(endPeriod)) {
1147
1171
  return endPeriod;
1148
1172
  }
1149
- const type = (0, values_1.toNumberRV)(args[5]);
1173
+ const type = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5]));
1150
1174
  if ((0, values_1.isError)(type)) {
1151
1175
  return type;
1152
1176
  }
@@ -1164,8 +1188,10 @@ const fnCUMPRINC = args => {
1164
1188
  return values_1.ERRORS.NUM;
1165
1189
  }
1166
1190
  let cumPrinc = 0;
1191
+ // PMT is constant across all periods — hoist it out of the loop
1192
+ // rather than recomputing the same value `e - s + 1` times.
1193
+ const pmtVal = pmtRaw(rate.value, nper.value, pv.value, 0, type.value);
1167
1194
  for (let p = s; p <= e; p++) {
1168
- const pmtVal = pmtRaw(rate.value, nper.value, pv.value, 0, type.value);
1169
1195
  const ipmtVal = ipmtRaw(rate.value, p, nper.value, pv.value, 0, type.value);
1170
1196
  cumPrinc += pmtVal - ipmtVal;
1171
1197
  }
@@ -1173,27 +1199,27 @@ const fnCUMPRINC = args => {
1173
1199
  };
1174
1200
  exports.fnCUMPRINC = fnCUMPRINC;
1175
1201
  const fnCUMIPMT = args => {
1176
- const rate = (0, values_1.toNumberRV)(args[0]);
1202
+ const rate = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1177
1203
  if ((0, values_1.isError)(rate)) {
1178
1204
  return rate;
1179
1205
  }
1180
- const nper = (0, values_1.toNumberRV)(args[1]);
1206
+ const nper = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1181
1207
  if ((0, values_1.isError)(nper)) {
1182
1208
  return nper;
1183
1209
  }
1184
- const pv = (0, values_1.toNumberRV)(args[2]);
1210
+ const pv = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1185
1211
  if ((0, values_1.isError)(pv)) {
1186
1212
  return pv;
1187
1213
  }
1188
- const startPeriod = (0, values_1.toNumberRV)(args[3]);
1214
+ const startPeriod = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1189
1215
  if ((0, values_1.isError)(startPeriod)) {
1190
1216
  return startPeriod;
1191
1217
  }
1192
- const endPeriod = (0, values_1.toNumberRV)(args[4]);
1218
+ const endPeriod = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
1193
1219
  if ((0, values_1.isError)(endPeriod)) {
1194
1220
  return endPeriod;
1195
1221
  }
1196
- const type = (0, values_1.toNumberRV)(args[5]);
1222
+ const type = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5]));
1197
1223
  if ((0, values_1.isError)(type)) {
1198
1224
  return type;
1199
1225
  }
@@ -1217,11 +1243,11 @@ const fnCUMIPMT = args => {
1217
1243
  };
1218
1244
  exports.fnCUMIPMT = fnCUMIPMT;
1219
1245
  const fnDOLLARDE = args => {
1220
- const fractionalDollar = (0, values_1.toNumberRV)(args[0]);
1246
+ const fractionalDollar = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1221
1247
  if ((0, values_1.isError)(fractionalDollar)) {
1222
1248
  return fractionalDollar;
1223
1249
  }
1224
- const fraction = (0, values_1.toNumberRV)(args[1]);
1250
+ const fraction = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1225
1251
  if ((0, values_1.isError)(fraction)) {
1226
1252
  return fraction;
1227
1253
  }
@@ -1245,11 +1271,11 @@ const fnDOLLARDE = args => {
1245
1271
  };
1246
1272
  exports.fnDOLLARDE = fnDOLLARDE;
1247
1273
  const fnDOLLARFR = args => {
1248
- const decimalDollar = (0, values_1.toNumberRV)(args[0]);
1274
+ const decimalDollar = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1249
1275
  if ((0, values_1.isError)(decimalDollar)) {
1250
1276
  return decimalDollar;
1251
1277
  }
1252
- const fraction = (0, values_1.toNumberRV)(args[1]);
1278
+ const fraction = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1253
1279
  if ((0, values_1.isError)(fraction)) {
1254
1280
  return fraction;
1255
1281
  }
@@ -1286,23 +1312,23 @@ function validateBasis(basis) {
1286
1312
  return null;
1287
1313
  }
1288
1314
  const fnDISC = args => {
1289
- const settlement = (0, values_1.toNumberRV)(args[0]);
1315
+ const settlement = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1290
1316
  if ((0, values_1.isError)(settlement)) {
1291
1317
  return settlement;
1292
1318
  }
1293
- const maturity = (0, values_1.toNumberRV)(args[1]);
1319
+ const maturity = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1294
1320
  if ((0, values_1.isError)(maturity)) {
1295
1321
  return maturity;
1296
1322
  }
1297
- const pr = (0, values_1.toNumberRV)(args[2]);
1323
+ const pr = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1298
1324
  if ((0, values_1.isError)(pr)) {
1299
1325
  return pr;
1300
1326
  }
1301
- const redemption = (0, values_1.toNumberRV)(args[3]);
1327
+ const redemption = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1302
1328
  if ((0, values_1.isError)(redemption)) {
1303
1329
  return redemption;
1304
1330
  }
1305
- const basis = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
1331
+ const basis = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
1306
1332
  if ((0, values_1.isError)(basis)) {
1307
1333
  return basis;
1308
1334
  }
@@ -1324,23 +1350,23 @@ const fnDISC = args => {
1324
1350
  };
1325
1351
  exports.fnDISC = fnDISC;
1326
1352
  const fnPRICEDISC = args => {
1327
- const settlement = (0, values_1.toNumberRV)(args[0]);
1353
+ const settlement = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1328
1354
  if ((0, values_1.isError)(settlement)) {
1329
1355
  return settlement;
1330
1356
  }
1331
- const maturity = (0, values_1.toNumberRV)(args[1]);
1357
+ const maturity = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1332
1358
  if ((0, values_1.isError)(maturity)) {
1333
1359
  return maturity;
1334
1360
  }
1335
- const disc = (0, values_1.toNumberRV)(args[2]);
1361
+ const disc = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1336
1362
  if ((0, values_1.isError)(disc)) {
1337
1363
  return disc;
1338
1364
  }
1339
- const redemption = (0, values_1.toNumberRV)(args[3]);
1365
+ const redemption = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1340
1366
  if ((0, values_1.isError)(redemption)) {
1341
1367
  return redemption;
1342
1368
  }
1343
- const basis = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
1369
+ const basis = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
1344
1370
  if ((0, values_1.isError)(basis)) {
1345
1371
  return basis;
1346
1372
  }
@@ -1356,23 +1382,23 @@ const fnPRICEDISC = args => {
1356
1382
  };
1357
1383
  exports.fnPRICEDISC = fnPRICEDISC;
1358
1384
  const fnYIELDDISC = args => {
1359
- const settlement = (0, values_1.toNumberRV)(args[0]);
1385
+ const settlement = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1360
1386
  if ((0, values_1.isError)(settlement)) {
1361
1387
  return settlement;
1362
1388
  }
1363
- const maturity = (0, values_1.toNumberRV)(args[1]);
1389
+ const maturity = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1364
1390
  if ((0, values_1.isError)(maturity)) {
1365
1391
  return maturity;
1366
1392
  }
1367
- const pr = (0, values_1.toNumberRV)(args[2]);
1393
+ const pr = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1368
1394
  if ((0, values_1.isError)(pr)) {
1369
1395
  return pr;
1370
1396
  }
1371
- const redemption = (0, values_1.toNumberRV)(args[3]);
1397
+ const redemption = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1372
1398
  if ((0, values_1.isError)(redemption)) {
1373
1399
  return redemption;
1374
1400
  }
1375
- const basis = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
1401
+ const basis = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
1376
1402
  if ((0, values_1.isError)(basis)) {
1377
1403
  return basis;
1378
1404
  }
@@ -1391,23 +1417,23 @@ const fnYIELDDISC = args => {
1391
1417
  };
1392
1418
  exports.fnYIELDDISC = fnYIELDDISC;
1393
1419
  const fnRECEIVED = args => {
1394
- const settlement = (0, values_1.toNumberRV)(args[0]);
1420
+ const settlement = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1395
1421
  if ((0, values_1.isError)(settlement)) {
1396
1422
  return settlement;
1397
1423
  }
1398
- const maturity = (0, values_1.toNumberRV)(args[1]);
1424
+ const maturity = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1399
1425
  if ((0, values_1.isError)(maturity)) {
1400
1426
  return maturity;
1401
1427
  }
1402
- const investment = (0, values_1.toNumberRV)(args[2]);
1428
+ const investment = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1403
1429
  if ((0, values_1.isError)(investment)) {
1404
1430
  return investment;
1405
1431
  }
1406
- const disc = (0, values_1.toNumberRV)(args[3]);
1432
+ const disc = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1407
1433
  if ((0, values_1.isError)(disc)) {
1408
1434
  return disc;
1409
1435
  }
1410
- const basis = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
1436
+ const basis = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
1411
1437
  if ((0, values_1.isError)(basis)) {
1412
1438
  return basis;
1413
1439
  }
@@ -1427,23 +1453,23 @@ const fnRECEIVED = args => {
1427
1453
  };
1428
1454
  exports.fnRECEIVED = fnRECEIVED;
1429
1455
  const fnINTRATE = args => {
1430
- const settlement = (0, values_1.toNumberRV)(args[0]);
1456
+ const settlement = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1431
1457
  if ((0, values_1.isError)(settlement)) {
1432
1458
  return settlement;
1433
1459
  }
1434
- const maturity = (0, values_1.toNumberRV)(args[1]);
1460
+ const maturity = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1435
1461
  if ((0, values_1.isError)(maturity)) {
1436
1462
  return maturity;
1437
1463
  }
1438
- const investment = (0, values_1.toNumberRV)(args[2]);
1464
+ const investment = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1439
1465
  if ((0, values_1.isError)(investment)) {
1440
1466
  return investment;
1441
1467
  }
1442
- const redemption = (0, values_1.toNumberRV)(args[3]);
1468
+ const redemption = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1443
1469
  if ((0, values_1.isError)(redemption)) {
1444
1470
  return redemption;
1445
1471
  }
1446
- const basis = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
1472
+ const basis = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
1447
1473
  if ((0, values_1.isError)(basis)) {
1448
1474
  return basis;
1449
1475
  }
@@ -1661,31 +1687,31 @@ function validateBondBasis(frequency, basis) {
1661
1687
  * A = days from beginning of coupon period to settlement
1662
1688
  */
1663
1689
  const fnPRICE = args => {
1664
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
1690
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1665
1691
  if ((0, values_1.isError)(settlementRV)) {
1666
1692
  return settlementRV;
1667
1693
  }
1668
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
1694
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1669
1695
  if ((0, values_1.isError)(maturityRV)) {
1670
1696
  return maturityRV;
1671
1697
  }
1672
- const rateRV = (0, values_1.toNumberRV)(args[2]);
1698
+ const rateRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1673
1699
  if ((0, values_1.isError)(rateRV)) {
1674
1700
  return rateRV;
1675
1701
  }
1676
- const yieldRV = (0, values_1.toNumberRV)(args[3]);
1702
+ const yieldRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1677
1703
  if ((0, values_1.isError)(yieldRV)) {
1678
1704
  return yieldRV;
1679
1705
  }
1680
- const redemptionRV = (0, values_1.toNumberRV)(args[4]);
1706
+ const redemptionRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
1681
1707
  if ((0, values_1.isError)(redemptionRV)) {
1682
1708
  return redemptionRV;
1683
1709
  }
1684
- const frequencyRV = (0, values_1.toNumberRV)(args[5]);
1710
+ const frequencyRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5]));
1685
1711
  if ((0, values_1.isError)(frequencyRV)) {
1686
1712
  return frequencyRV;
1687
1713
  }
1688
- const basisRV = args.length > 6 ? (0, values_1.toNumberRV)(args[6]) : (0, values_1.rvNumber)(0);
1714
+ const basisRV = args.length > 6 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[6])) : (0, values_1.rvNumber)(0);
1689
1715
  if ((0, values_1.isError)(basisRV)) {
1690
1716
  return basisRV;
1691
1717
  }
@@ -1736,31 +1762,31 @@ exports.fnPRICE = fnPRICE;
1736
1762
  * realistic bond scenarios) followed by a light Newton polish.
1737
1763
  */
1738
1764
  const fnYIELD = args => {
1739
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
1765
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1740
1766
  if ((0, values_1.isError)(settlementRV)) {
1741
1767
  return settlementRV;
1742
1768
  }
1743
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
1769
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1744
1770
  if ((0, values_1.isError)(maturityRV)) {
1745
1771
  return maturityRV;
1746
1772
  }
1747
- const rateRV = (0, values_1.toNumberRV)(args[2]);
1773
+ const rateRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1748
1774
  if ((0, values_1.isError)(rateRV)) {
1749
1775
  return rateRV;
1750
1776
  }
1751
- const prRV = (0, values_1.toNumberRV)(args[3]);
1777
+ const prRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1752
1778
  if ((0, values_1.isError)(prRV)) {
1753
1779
  return prRV;
1754
1780
  }
1755
- const redemptionRV = (0, values_1.toNumberRV)(args[4]);
1781
+ const redemptionRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
1756
1782
  if ((0, values_1.isError)(redemptionRV)) {
1757
1783
  return redemptionRV;
1758
1784
  }
1759
- const frequencyRV = (0, values_1.toNumberRV)(args[5]);
1785
+ const frequencyRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5]));
1760
1786
  if ((0, values_1.isError)(frequencyRV)) {
1761
1787
  return frequencyRV;
1762
1788
  }
1763
- const basisRV = args.length > 6 ? (0, values_1.toNumberRV)(args[6]) : (0, values_1.rvNumber)(0);
1789
+ const basisRV = args.length > 6 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[6])) : (0, values_1.rvNumber)(0);
1764
1790
  if ((0, values_1.isError)(basisRV)) {
1765
1791
  return basisRV;
1766
1792
  }
@@ -1824,27 +1850,27 @@ exports.fnYIELD = fnYIELD;
1824
1850
  * weighted by present value. Expressed in years.
1825
1851
  */
1826
1852
  const fnDURATION = args => {
1827
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
1853
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1828
1854
  if ((0, values_1.isError)(settlementRV)) {
1829
1855
  return settlementRV;
1830
1856
  }
1831
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
1857
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1832
1858
  if ((0, values_1.isError)(maturityRV)) {
1833
1859
  return maturityRV;
1834
1860
  }
1835
- const couponRV = (0, values_1.toNumberRV)(args[2]);
1861
+ const couponRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1836
1862
  if ((0, values_1.isError)(couponRV)) {
1837
1863
  return couponRV;
1838
1864
  }
1839
- const yieldRV = (0, values_1.toNumberRV)(args[3]);
1865
+ const yieldRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1840
1866
  if ((0, values_1.isError)(yieldRV)) {
1841
1867
  return yieldRV;
1842
1868
  }
1843
- const frequencyRV = (0, values_1.toNumberRV)(args[4]);
1869
+ const frequencyRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
1844
1870
  if ((0, values_1.isError)(frequencyRV)) {
1845
1871
  return frequencyRV;
1846
1872
  }
1847
- const basisRV = args.length > 5 ? (0, values_1.toNumberRV)(args[5]) : (0, values_1.rvNumber)(0);
1873
+ const basisRV = args.length > 5 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5])) : (0, values_1.rvNumber)(0);
1848
1874
  if ((0, values_1.isError)(basisRV)) {
1849
1875
  return basisRV;
1850
1876
  }
@@ -1892,11 +1918,11 @@ const fnMDURATION = args => {
1892
1918
  if (dur.kind !== 1 /* RVKind.Number */) {
1893
1919
  return dur;
1894
1920
  }
1895
- const yieldRV = (0, values_1.toNumberRV)(args[3]);
1921
+ const yieldRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1896
1922
  if ((0, values_1.isError)(yieldRV)) {
1897
1923
  return yieldRV;
1898
1924
  }
1899
- const frequencyRV = (0, values_1.toNumberRV)(args[4]);
1925
+ const frequencyRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
1900
1926
  if ((0, values_1.isError)(frequencyRV)) {
1901
1927
  return frequencyRV;
1902
1928
  }
@@ -1911,28 +1937,28 @@ exports.fnMDURATION = fnMDURATION;
1911
1937
  * accrued interest from issue to settlement as par * rate * dcf(issue, settlement, basis).
1912
1938
  */
1913
1939
  const fnACCRINT = args => {
1914
- const issueRV = (0, values_1.toNumberRV)(args[0]);
1940
+ const issueRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1915
1941
  if ((0, values_1.isError)(issueRV)) {
1916
1942
  return issueRV;
1917
1943
  }
1918
1944
  // first_interest (args[1]) is unused in the simplified implementation.
1919
- const settlementRV = (0, values_1.toNumberRV)(args[2]);
1945
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1920
1946
  if ((0, values_1.isError)(settlementRV)) {
1921
1947
  return settlementRV;
1922
1948
  }
1923
- const rateRV = (0, values_1.toNumberRV)(args[3]);
1949
+ const rateRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1924
1950
  if ((0, values_1.isError)(rateRV)) {
1925
1951
  return rateRV;
1926
1952
  }
1927
- const parRV = (0, values_1.toNumberRV)(args[4]);
1953
+ const parRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
1928
1954
  if ((0, values_1.isError)(parRV)) {
1929
1955
  return parRV;
1930
1956
  }
1931
- const frequencyRV = (0, values_1.toNumberRV)(args[5]);
1957
+ const frequencyRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5]));
1932
1958
  if ((0, values_1.isError)(frequencyRV)) {
1933
1959
  return frequencyRV;
1934
1960
  }
1935
- const basisRV = args.length > 6 ? (0, values_1.toNumberRV)(args[6]) : (0, values_1.rvNumber)(0);
1961
+ const basisRV = args.length > 6 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[6])) : (0, values_1.rvNumber)(0);
1936
1962
  if ((0, values_1.isError)(basisRV)) {
1937
1963
  return basisRV;
1938
1964
  }
@@ -1959,23 +1985,23 @@ exports.fnACCRINT = fnACCRINT;
1959
1985
  * result = par × rate × dayCountFraction(issue, settlement, basis)
1960
1986
  */
1961
1987
  const fnACCRINTM = args => {
1962
- const issueRV = (0, values_1.toNumberRV)(args[0]);
1988
+ const issueRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
1963
1989
  if ((0, values_1.isError)(issueRV)) {
1964
1990
  return issueRV;
1965
1991
  }
1966
- const settlementRV = (0, values_1.toNumberRV)(args[1]);
1992
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
1967
1993
  if ((0, values_1.isError)(settlementRV)) {
1968
1994
  return settlementRV;
1969
1995
  }
1970
- const rateRV = (0, values_1.toNumberRV)(args[2]);
1996
+ const rateRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
1971
1997
  if ((0, values_1.isError)(rateRV)) {
1972
1998
  return rateRV;
1973
1999
  }
1974
- const parRV = (0, values_1.toNumberRV)(args[3]);
2000
+ const parRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
1975
2001
  if ((0, values_1.isError)(parRV)) {
1976
2002
  return parRV;
1977
2003
  }
1978
- const basisRV = args.length > 4 ? (0, values_1.toNumberRV)(args[4]) : (0, values_1.rvNumber)(0);
2004
+ const basisRV = args.length > 4 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4])) : (0, values_1.rvNumber)(0);
1979
2005
  if ((0, values_1.isError)(basisRV)) {
1980
2006
  return basisRV;
1981
2007
  }
@@ -1998,15 +2024,15 @@ exports.fnACCRINTM = fnACCRINTM;
1998
2024
  * where DSM is days from settlement to maturity.
1999
2025
  */
2000
2026
  const fnTBILLPRICE = args => {
2001
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
2027
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
2002
2028
  if ((0, values_1.isError)(settlementRV)) {
2003
2029
  return settlementRV;
2004
2030
  }
2005
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
2031
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
2006
2032
  if ((0, values_1.isError)(maturityRV)) {
2007
2033
  return maturityRV;
2008
2034
  }
2009
- const discountRV = (0, values_1.toNumberRV)(args[2]);
2035
+ const discountRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
2010
2036
  if ((0, values_1.isError)(discountRV)) {
2011
2037
  return discountRV;
2012
2038
  }
@@ -2033,15 +2059,15 @@ exports.fnTBILLPRICE = fnTBILLPRICE;
2033
2059
  * yield = (100 - pr) / pr × (360 / DSM)
2034
2060
  */
2035
2061
  const fnTBILLYIELD = args => {
2036
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
2062
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
2037
2063
  if ((0, values_1.isError)(settlementRV)) {
2038
2064
  return settlementRV;
2039
2065
  }
2040
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
2066
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
2041
2067
  if ((0, values_1.isError)(maturityRV)) {
2042
2068
  return maturityRV;
2043
2069
  }
2044
- const prRV = (0, values_1.toNumberRV)(args[2]);
2070
+ const prRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
2045
2071
  if ((0, values_1.isError)(prRV)) {
2046
2072
  return prRV;
2047
2073
  }
@@ -2063,15 +2089,15 @@ exports.fnTBILLYIELD = fnTBILLYIELD;
2063
2089
  * TBILLEQ = (365 × discount) / (360 - discount × DSM)
2064
2090
  */
2065
2091
  const fnTBILLEQ = args => {
2066
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
2092
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
2067
2093
  if ((0, values_1.isError)(settlementRV)) {
2068
2094
  return settlementRV;
2069
2095
  }
2070
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
2096
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
2071
2097
  if ((0, values_1.isError)(maturityRV)) {
2072
2098
  return maturityRV;
2073
2099
  }
2074
- const discountRV = (0, values_1.toNumberRV)(args[2]);
2100
+ const discountRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
2075
2101
  if ((0, values_1.isError)(discountRV)) {
2076
2102
  return discountRV;
2077
2103
  }
@@ -2102,27 +2128,27 @@ exports.fnTBILLEQ = fnTBILLEQ;
2102
2128
  * price = (100 + DIM × rate × 100) / (1 + DSM × yld) - A × rate × 100
2103
2129
  */
2104
2130
  const fnPRICEMAT = args => {
2105
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
2131
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
2106
2132
  if ((0, values_1.isError)(settlementRV)) {
2107
2133
  return settlementRV;
2108
2134
  }
2109
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
2135
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
2110
2136
  if ((0, values_1.isError)(maturityRV)) {
2111
2137
  return maturityRV;
2112
2138
  }
2113
- const issueRV = (0, values_1.toNumberRV)(args[2]);
2139
+ const issueRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
2114
2140
  if ((0, values_1.isError)(issueRV)) {
2115
2141
  return issueRV;
2116
2142
  }
2117
- const rateRV = (0, values_1.toNumberRV)(args[3]);
2143
+ const rateRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
2118
2144
  if ((0, values_1.isError)(rateRV)) {
2119
2145
  return rateRV;
2120
2146
  }
2121
- const yldRV = (0, values_1.toNumberRV)(args[4]);
2147
+ const yldRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
2122
2148
  if ((0, values_1.isError)(yldRV)) {
2123
2149
  return yldRV;
2124
2150
  }
2125
- const basisRV = args.length > 5 ? (0, values_1.toNumberRV)(args[5]) : (0, values_1.rvNumber)(0);
2151
+ const basisRV = args.length > 5 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5])) : (0, values_1.rvNumber)(0);
2126
2152
  if ((0, values_1.isError)(basisRV)) {
2127
2153
  return basisRV;
2128
2154
  }
@@ -2159,27 +2185,27 @@ exports.fnPRICEMAT = fnPRICEMAT;
2159
2185
  * yield = ((1 + DIM × rate) / (pr/100 + A × rate) - 1) / DSM
2160
2186
  */
2161
2187
  const fnYIELDMAT = args => {
2162
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
2188
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
2163
2189
  if ((0, values_1.isError)(settlementRV)) {
2164
2190
  return settlementRV;
2165
2191
  }
2166
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
2192
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
2167
2193
  if ((0, values_1.isError)(maturityRV)) {
2168
2194
  return maturityRV;
2169
2195
  }
2170
- const issueRV = (0, values_1.toNumberRV)(args[2]);
2196
+ const issueRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
2171
2197
  if ((0, values_1.isError)(issueRV)) {
2172
2198
  return issueRV;
2173
2199
  }
2174
- const rateRV = (0, values_1.toNumberRV)(args[3]);
2200
+ const rateRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3]));
2175
2201
  if ((0, values_1.isError)(rateRV)) {
2176
2202
  return rateRV;
2177
2203
  }
2178
- const prRV = (0, values_1.toNumberRV)(args[4]);
2204
+ const prRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[4]));
2179
2205
  if ((0, values_1.isError)(prRV)) {
2180
2206
  return prRV;
2181
2207
  }
2182
- const basisRV = args.length > 5 ? (0, values_1.toNumberRV)(args[5]) : (0, values_1.rvNumber)(0);
2208
+ const basisRV = args.length > 5 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[5])) : (0, values_1.rvNumber)(0);
2183
2209
  if ((0, values_1.isError)(basisRV)) {
2184
2210
  return basisRV;
2185
2211
  }
@@ -2220,19 +2246,19 @@ exports.fnYIELDMAT = fnYIELDMAT;
2220
2246
  * settlement/maturity/frequency/basis values, or an error.
2221
2247
  */
2222
2248
  function parseCoupArgs(args) {
2223
- const settlementRV = (0, values_1.toNumberRV)(args[0]);
2249
+ const settlementRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[0]));
2224
2250
  if ((0, values_1.isError)(settlementRV)) {
2225
2251
  return settlementRV;
2226
2252
  }
2227
- const maturityRV = (0, values_1.toNumberRV)(args[1]);
2253
+ const maturityRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[1]));
2228
2254
  if ((0, values_1.isError)(maturityRV)) {
2229
2255
  return maturityRV;
2230
2256
  }
2231
- const frequencyRV = (0, values_1.toNumberRV)(args[2]);
2257
+ const frequencyRV = (0, values_1.toNumberRV)((0, values_1.topLeft)(args[2]));
2232
2258
  if ((0, values_1.isError)(frequencyRV)) {
2233
2259
  return frequencyRV;
2234
2260
  }
2235
- const basisRV = args.length > 3 ? (0, values_1.toNumberRV)(args[3]) : (0, values_1.rvNumber)(0);
2261
+ const basisRV = args.length > 3 ? (0, values_1.toNumberRV)((0, values_1.topLeft)(args[3])) : (0, values_1.rvNumber)(0);
2236
2262
  if ((0, values_1.isError)(basisRV)) {
2237
2263
  return basisRV;
2238
2264
  }