Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Demonstrandum/speed-comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Demonstrandum committed Nov 14, 2022
2 parents 1e5cbf2 3116f29 commit 82e8dfd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 88,13 @@ The list of Contributors is automatically generated.
<sub style="font-size:14px"><b>Francesco Alemanno</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/viscropst>
<img src=https://avatars.githubusercontent.com/u/16207250?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Yu Zhu/>
<br />
<sub style="font-size:14px"><b>Yu Zhu</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/Moelf>
<img src=https://avatars.githubusercontent.com/u/5306213?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Jerry Ling/>
Expand All @@ -109,13 116,6 @@ The list of Contributors is automatically generated.
<sub style="font-size:14px"><b>0xB00B</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/viscropst>
<img src=https://avatars.githubusercontent.com/u/16207250?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Yu Zhu/>
<br />
<sub style="font-size:14px"><b>Yu Zhu</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
Expand Down Expand Up @@ -169,6 169,13 @@ The list of Contributors is automatically generated.
<sub style="font-size:14px"><b>mattn</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/Demonstrandum>
<img src=https://avatars.githubusercontent.com/u/26842759?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=S Knutsen/>
<br />
<sub style="font-size:14px"><b>S Knutsen</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/LazyKernel>
<img src=https://avatars.githubusercontent.com/u/10184101?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=LazyKernel/>
Expand All @@ -190,6 197,15 @@ The list of Contributors is automatically generated.
<sub style="font-size:14px"><b>Oscar Smith</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/PallHaraldsson>
<img src=https://avatars.githubusercontent.com/u/8005416?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Páll Haraldsson/>
<br />
<sub style="font-size:14px"><b>Páll Haraldsson</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/DirkieDurky>
<img src=https://avatars.githubusercontent.com/u/72947540?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=DirkieDurky/>
Expand All @@ -204,8 220,6 @@ The list of Contributors is automatically generated.
<sub style="font-size:14px"><b>Gui Zhen Wei</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/PatrickTheDev>
<img src=https://avatars.githubusercontent.com/u/69093169?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=RDPatrickTheDev/>
Expand Down Expand Up @@ -234,22 248,29 @@ The list of Contributors is automatically generated.
<sub style="font-size:14px"><b>Thomas A Caswell</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/demotomohiro>
<img src=https://avatars.githubusercontent.com/u/1882512?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Tomohiro/>
<br />
<sub style="font-size:14px"><b>Tomohiro</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/genmeblog>
<img src=https://avatars.githubusercontent.com/u/38646601?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=genmeblog/>
<br />
<sub style="font-size:14px"><b>genmeblog</b></sub>
</a>
</td>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/mosmeh>
<img src=https://avatars.githubusercontent.com/u/1721932?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Yuta Imazu/>
<br />
<sub style="font-size:14px"><b>Yuta Imazu</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
<a href=https://github.com/motoshira>
<img src=https://avatars.githubusercontent.com/u/51407064?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Kohei Hosoki/>
Expand Down
2 changes: 1 addition & 1 deletion src/leibniz.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@

(defn calc-pi-leibniz
"Translation of Java solution to Clojure"
[rounds]
[^long rounds]
(let [end ( 2 rounds)]
(loop [i 2 x 1.0 pi 1.0]
(if (= i end)
Expand Down
6 changes: 4 additions & 2 deletions src/leibniz.hs
Original file line number Diff line number Diff line change
@@ -1,12 1,14 @@
{-# LANGUAGE BangPatterns #-}

{- | A more direct port of the C version. -}
module Main where

-- | Computes partial alternating series converging
-- to π/4=arctan(1) up n terms.
leibniz :: Int -> Double
leibniz n = partial 2 1.0 where
leibniz !n = partial 2 1.0 where
partial :: Int -> Double -> Double
partial i qpi
partial !i !qpi
| i == n 2 = qpi
| otherwise = partial (i 1) $ qpi - powNeg1 i * inv (2*i - 1)
inv = recip . fromIntegral
Expand Down
19 changes: 10 additions & 9 deletions src/leibniz_ux4.jl
Original file line number Diff line number Diff line change
@@ -1,17 1,18 @@
function f(rounds)
pi = 1.0
x = -1.0
pi = -1.0f0
# x = -1.0
r2 = rounds 2
vend = r2 - r2 % 4
@simd for i in 2:4:r2
pi = x / (2.0 * i - 1.0) -
x / (2.0 * i 1.0)
x / (2.0 * i 3.0) -
x / (2.0 * i 5.0)
@simd for i in 4:8:(r2*2)
pi = inv(i - 1.0f0) -
inv(i 1.0f0)
inv(i 3.0f0) -
inv(i 5.0f0)
end
pi = -pi
for i in vend 1:r2
pi = 1.0 / (2.0 * (i 0.0) - 1.0)
x = -x
pi = 1.0 / (2.0 * (i 0.0) - 1.0)
# x = -x
end
return pi*4
end
Expand Down

0 comments on commit 82e8dfd

Please sign in to comment.