| 1 | module scheme |
| 2 | |
| 3 | import math |
| 4 | import math.complex |
| 5 | |
| 6 | // Independent full-log references and exact binary-rational quotient both |
| 7 | // require the least subnormal here. Normalized products remain normal; the |
| 8 | // second rounding occurs only when the quotient's exponent is restored. |
| 9 | fn complex_scale_rounding_input() (f64, f64) { |
| 10 | return math.f64_from_bits(0x419e8785e6432e44), math.f64_from_bits(0x001d205903b5161e) |
| 11 | } |
| 12 | |
| 13 | fn test_complex_division_final_scaling_keeps_minimum_subnormal_without_tiny_products() { |
| 14 | x, y := complex_scale_rounding_input() |
| 15 | for xs in [1.0, -1.0] { |
| 16 | for ys in [1.0, -1.0] { |
| 17 | answer := scaled_complex_divide(complex.complex(ys * y, 0), complex.complex(xs * x, 1)) or { panic(err.msg()) } |
| 18 | assert answer.im == -ys * math.f64_from_bits(1) |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | fn test_complex_division_final_scaling_regression_reaches_scheme_arithmetic() { |
| 24 | mut vm := new() |
| 25 | x, y := complex_scale_rounding_input() |
| 26 | for ys in [1.0, -1.0] { |
| 27 | answer := inexact_complex(vm.call(vm.lookup('/') or { panic(err.msg()) }, [ |
| 28 | real(ys * y), |
| 29 | owned_inexact_complex(complex.complex(x, 1)), |
| 30 | ]) or { panic(err.msg()) }) or { panic(err.msg()) } |
| 31 | assert answer.im == -ys * math.f64_from_bits(1) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | fn test_complex_atan_thin_axis_final_scaling_regression_preserves_tiny_imaginary_part() { |
| 36 | mut vm := new() |
| 37 | x, y := complex_scale_rounding_input() |
| 38 | for xs in [1.0, -1.0] { |
| 39 | for ys in [1.0, -1.0] { |
| 40 | answer := inexact_complex(vm.call(vm.lookup('atan') or { panic(err.msg()) }, [owned_inexact_complex(complex.complex(xs * x, ys * y))]) or { panic(err.msg()) }) or { panic(err.msg()) } |
| 41 | assert answer.im == ys * math.f64_from_bits(1) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |