This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub module approx-recip | |
import smooth | |
fun approx-recip(iters : int, x : a) : <smooth<a>,div> a { | |
var acc := c(1.0) | |
var prev := c(1.0) | |
repeat(iters) { | |
prev := (prev *. (~.)(x -. c(1.0))) | |
acc := (acc +. prev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.Array.Accelerate as A | |
import Data.Array.Accelerate.LLVM.Native | |
g :: Scalar Double -> Scalar Double | |
g = (runN (A.map f :: Acc (Scalar Double) -> Acc (Scalar Double))) | |
where | |
f x = let y = recip x | |
b = (-y) * y |