( remoteTypeId: number, localTypeId: number, value: string, converter: string, )
| 482 | } |
| 483 | |
| 484 | function scalarToFloatExpr( |
| 485 | remoteTypeId: number, |
| 486 | localTypeId: number, |
| 487 | value: string, |
| 488 | converter: string, |
| 489 | ): string | null { |
| 490 | const method = floatMethod("Float", localTypeId); |
| 491 | if (method === null) { |
| 492 | return null; |
| 493 | } |
| 494 | switch (remoteTypeId) { |
| 495 | case TypeId.BOOL: |
| 496 | return `(${value} ? 1 : 0)`; |
| 497 | case TypeId.STRING: |
| 498 | return `${converter}.stringTo${method}(${value})`; |
| 499 | case TypeId.DECIMAL: |
| 500 | return `${converter}.decimalTo${method}(${value})`; |
| 501 | case TypeId.FLOAT16: |
| 502 | case TypeId.BFLOAT16: |
| 503 | case TypeId.FLOAT32: |
| 504 | case TypeId.FLOAT64: |
| 505 | if (remoteTypeId === localTypeId) { |
| 506 | return value; |
| 507 | } |
| 508 | return `${converter}.floatTo${method}(${value})`; |
| 509 | default: |
| 510 | if (integerRangeFitsFloat(remoteTypeId, localTypeId)) { |
| 511 | return `Number(${value})`; |
| 512 | } |
| 513 | return `${converter}.integerTo${method}(${value})`; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | function floatMethod(prefix: string, localTypeId: number): string | null { |
| 518 | switch (localTypeId) { |
no test coverage detected