# LLVM version of modf

**URL:** https://discourse.julialang.org/t/llvm-version-of-modf/6738
**Category:** Internals & Design
**Created:** [October 28, 2017, 9:58am UTC](https://discourse.julialang.org/t/llvm-version-of-modf/6738 "2017-10-28T09:58:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [October 28, 2017, 9:58am UTC](https://discourse.julialang.org/t/llvm-version-of-modf/6738/1 "2017-10-28T09:58:45Z")

</div>

Is LLVM version of `modf` guaranteed to be safer or faster for some input or platform, compared to the fallback method

```julia
modf(x) = rem(x,one(x)), trunc(x)

```

? On my machine (64-bit GNU/Linux), the fallback method is much faster than LLVM with `Float64` numbers:

```julia
julia> test_llvm_modf() = for x in -1000:0.001:1000; modf(x); end
test_llvm_modf (generic function with 1 method)

julia> @benchmark test_llvm_modf()
BenchmarkTools.Trial: 
  memory estimate: 0 bytes
  allocs estimate: 0
  --------------
  minimum time: 16.505 ms (0.00% GC)
  median time: 16.613 ms (0.00% GC)
  mean time: 16.700 ms (0.00% GC)
  maximum time: 17.188 ms (0.00% GC)
  --------------
  samples: 300
  evals/sample: 1

julia> test_fallback_modf() = for x in -1000:0.001:1000; rem(x,one(x)), trunc(x); end
test_fallback_modf (generic function with 1 method)

julia> @benchmark test_fallback_modf()
BenchmarkTools.Trial: 
  memory estimate: 0 bytes
  allocs estimate: 0
  --------------
  minimum time: 589.929 μs (0.00% GC)
  median time: 589.941 μs (0.00% GC)
  mean time: 596.599 μs (0.00% GC)
  maximum time: 856.916 μs (0.00% GC)
  --------------
  samples: 8373
  evals/sample: 1

```

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [October 28, 2017, 12:53pm UTC](https://discourse.julialang.org/t/llvm-version-of-modf/6738/2 "2017-10-28T12:53:06Z")

</div>

1. There’s no LLVM version of `modf`

2. The main difference here is that the fallback version **IS** using LLVM intrinsics and the libm version is not.

In normal code it is usually expected that the result is used so this is not a major concern.
