| 1 | (* A code procedure that is a square root of d0 and ret is made in |
| 2 | place of its call (Gen.oneRealOp), as Math.sqrt is on x86-64; F32's |
| 3 | too. Its own here, as lib/Math.raz has x86-64's yet. *) |
| 4 | module Sqrt; |
| 5 | import Out, Fmt; |
| 6 | import SYSTEM; |
| 7 | |
| 8 | proc root(x: F64): F64; |
| 9 | code |
| 10 | fsqrt d0, d0; |
| 11 | ret; |
| 12 | end root; |
| 13 | |
| 14 | proc root32(x: F32): F32; |
| 15 | code |
| 16 | fsqrt s0, s0; |
| 17 | ret; |
| 18 | end root32; |
| 19 | |
| 20 | proc real(x: F64); |
| 21 | var b: [Fmt.ShortMost]U8; |
| 22 | begin |
| 23 | Out.str(Fmt.short(x, b)); Out.str(" "); |
| 24 | end; |
| 25 | |
| 26 | proc main*; |
| 27 | var x: F64; f: F32; |
| 28 | begin |
| 29 | x := 2.0; |
| 30 | real(root(x)); real(root(x * 8.0) + 1.0); |
| 31 | f := 2.0; |
| 32 | real(F64(root32(f))); real(root(-x)); Out.ln; |
| 33 | end; |
| 34 | |
| 35 | end Sqrt. |