(value: DecimalParts, localTypeId: number)
| 466 | } |
| 467 | |
| 468 | function exactFloat(value: DecimalParts, localTypeId: number): number { |
| 469 | let candidate = partsToNumber(value); |
| 470 | if (!Number.isFinite(candidate)) { |
| 471 | throw new Error( |
| 472 | "Scalar value is not exactly representable as a finite float.", |
| 473 | ); |
| 474 | } |
| 475 | switch (canonicalScalarTypeId(localTypeId)) { |
| 476 | case TypeId.FLOAT16: |
| 477 | candidate = fromFloat16Bits(toFloat16Bits(candidate)); |
| 478 | break; |
| 479 | case TypeId.BFLOAT16: |
| 480 | candidate = fromBFloat16Bits(toBFloat16Bits(candidate)); |
| 481 | break; |
| 482 | case TypeId.FLOAT32: |
| 483 | float32Array[0] = candidate; |
| 484 | candidate = float32Array[0]; |
| 485 | break; |
| 486 | default: |
| 487 | break; |
| 488 | } |
| 489 | if (!partsEqual(value, floatToParts(candidate))) { |
| 490 | throw new Error( |
| 491 | "Scalar value is not exactly representable by the target float type.", |
| 492 | ); |
| 493 | } |
| 494 | return candidate; |
| 495 | } |
| 496 | |
| 497 | function rangeCheckedInteger( |
| 498 | value: number | bigint, |
no test coverage detected