# Number of primes below a given number

**URL:** https://discourse.julialang.org/t/number-of-primes-below-a-given-number/58709
**Category:** Numerics
**Tags:** question
**Created:** [April 6, 2021, 6:36pm UTC](https://discourse.julialang.org/t/number-of-primes-below-a-given-number/58709 "2021-04-06T18:36:30Z")
**Posts on this page:** 1
**Showing post:** 37

<div class="post-metadata">

### Author: ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)
#### Post date: [April 7, 2021, 5:23pm UTC](https://discourse.julialang.org/t/number-of-primes-below-a-given-number/58709/37 "2021-04-07T17:23:38Z")

</div>

Yup - that would add a dependency to `primecount`, but I think that’s accessible. If any newcomers want to PR that, feel free to DM and I’ll mentor through the process.

Concretely, we wouldn’t want to spawn an external process with `run(...)` every time we want to count primes - we want to call to the C ABI with `@ccall` so that this is just a direct function call:

```julia
julia> myprimecount(x) = @ccall libprimecount.primecount_pi(x::Clonglong)::Clonglong
myprimecount (generic function with 1 method)

julia> @time myprimecount(1e8)
  0.001004 seconds
5761455

julia> @time myprimecount(1e14)
  0.149201 seconds
3204941750802

```

This would include wrapping up the different options in the [exposed command line options](https://github.com/kimwalisch/primecount#command-line-options) with appropriate dispatches.

This means that your mission, should you choose to accept it, would be a Pull Request to Primes.jl that

1. adds `primecount_jll` as a dependency (easy: fork the repo, dev the repo, activate the environment, and add `primecount` as a normal package).
2. add functions + dispatch for all the appropriate `@ccall`s exposed in the commandline options in `primecount`’s README.
3. add tests to make sure that everything you added works.

Once that’s done, a good open source citizen would also PR the `primecount` github repo’s README to add Primes.jl as an Julia wrapper in their documentation (and/ or buy `kimwalish` et al a coffee).

---

_[View the full topic](https://discourse.julialang.org/t/number-of-primes-below-a-given-number/58709)._
