# Zero() and TwicePrecision

**URL:** https://discourse.julialang.org/t/zero-and-twiceprecision/81208
**Category:** New to Julia
**Tags:** question, bug
**Created:** [May 17, 2022, 3:55pm UTC](https://discourse.julialang.org/t/zero-and-twiceprecision/81208 "2022-05-17T15:55:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![denshd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denshd/32/32247_2.png) [@denshd](https://discourse.julialang.org/u/denshd)
#### Post date: [May 17, 2022, 3:55pm UTC](https://discourse.julialang.org/t/zero-and-twiceprecision/81208/1 "2022-05-17T15:55:07Z")

</div>

Hello! I’ve recently found a weird behaviour of `StepLenRange`. Consider:

```julia
N = 10
faces = range(start=0, stop=1, length=(N + 1))
cells = range(start=(0 + faces.step), step=faces.step, length=N)

```

On my computer (`julia v.1.7.2`) it produces the following error:

```julia
ERROR: MethodError: no method matching zero(::Base.TwicePrecision{Float64})
Stacktrace:
 [1] _rangestyle(#unused#::Base.Unordered, #unused#::Base.ArithmeticUnknown, a::Base.TwicePrecision{Float64}, step::Base.TwicePrecision{Float64}, len::Int64)
   @ Base .\range.jl:168
 [2] range_start_step_length(a::Base.TwicePrecision{Float64}, step::Base.TwicePrecision{Float64}, len::Int64)

```

So, I think the problem with `0 + faces.step`. But is this a bug or a feature?🙂

EDIT:  
the following works well:

```julia
x = 0:0.1:1
step = x.step
0 + x.step

```

which produces:

```julia
Base.TwicePrecision{Float64}(0.1, -5.551115123125763e-18)

```

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [May 17, 2022, 4:02pm UTC](https://discourse.julialang.org/t/zero-and-twiceprecision/81208/2 "2022-05-17T16:02:46Z")

</div>

The fields of `StepLenRange`, like the fields of pretty much all other types in Base, and thoughout the julia ecosystem are not part of the public API for that type.  
And the `Base.TwicePrecision` type is intentionally not part of the public API for `Base`.

This works fine if you use the same `step` accessor function.

```julia
julia> N = 10
10

julia> faces = range(start=0, stop=1, length=(N + 1))
0.0:0.1:1.0

julia> cells = range(start=(0 + step(faces)), step=step(faces), length=N)
0.1:0.1:1.0

```

The `Base.TwicePrecision` type is an implementation detail.  
It’s intentionally very limitted and doesn’t subtype `Number` because things don’t work with it in general.

---

<div class="post-metadata">

### Author: ![denshd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denshd/32/32247_2.png) [@denshd](https://discourse.julialang.org/u/denshd)
#### Post date: [May 17, 2022, 4:13pm UTC](https://discourse.julialang.org/t/zero-and-twiceprecision/81208/3 "2022-05-17T16:13:16Z")

</div>

Thank you!  
I didn’t really know about

> accessor functions

and now I’m reading about

> public API

and how to recognize it 🙂
