# Different results when using 1 and 1.0 in expression

**URL:** https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617
**Category:** Numerics
**Tags:** question, numerics
**Created:** [August 14, 2025, 9:19pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617 "2025-08-14T21:19:52Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jogama](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jogama/32/49842_2.png) [@jogama](https://discourse.julialang.org/u/jogama)
#### Post date: [August 14, 2025, 9:19pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/1 "2025-08-14T21:19:52Z")

</div>

```julia-auto
d = (1+0im, 1.0+0im) (sqrt(exp(-d[1]) - 1),
                      sqrt(exp(-d[2]) - 1))
(0.0 + 0.7950600976206501im, 0.0 - 0.7950600976206501im)

```

also

```julia-auto
d = (1+0im, 1.0+0im); (sqrt(exp(-d[1]) - 1.0),
                       sqrt(exp(-d[2]) - 1.0))
(0.0 + 0.7950600976206501im, 0.0 - 0.7950600976206501im)

```

On Julia 1.11.3.

I’m curious as to why the results are different. Might anyone provide some insight into this?

To allay accusations of the XY problem, the context here is solving the unstable Bernoulli differential equation ẏ = by + y³, y(0) = 1, which has the closed-form solution

```julia-auto
y(t, b) = 1im * √b * exp(t) / sqrt(exp(2b*t)/(1+b) - 1) # *(±1). Assuming +1.
y(-2, Complex(1))
0.1359592602682265 - 0.0im
y(-2, Complex(1.0))
-0.1359592602682265 + 0.0im

```

I could just cast everything to float, sure. However, I’d like to understand what’s going on, if possible.

---

<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: [August 14, 2025, 9:24pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/2 "2025-08-14T21:24:15Z")

</div>

> [@jogama](#):
>
> ```julia-auto
> d = (1+0im, 1.0+0im) (sqrt(exp(-d[1]) - 1),
> sqrt(exp(-d[2]) - 1))
> (0.0 + 0.7950600976206501im, 0.0 - 0.7950600976206501im)
> 
> ```
> 
> also
> 
> ```julia-auto
> d = (1+0im, 1.0+0im); (sqrt(exp(-d[1]) - 1.0),
> sqrt(exp(-d[2]) - 1.0))
> (0.0 + 0.7950600976206501im, 0.0 - 0.7950600976206501im)
> 
> ```
> 
> On Julia 1.11.3.
> 
> I’m curious as to why the results are different.

I’m completely missing what’s different.

---

<div class="post-metadata">

### Author: ![jogama](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jogama/32/49842_2.png) [@jogama](https://discourse.julialang.org/u/jogama)
#### Post date: [August 14, 2025, 9:30pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/3 "2025-08-14T21:30:42Z")

</div>

> [@giordano](#):
>
> tely missing what’s diffe

Sorry, that could have been more clear. Using the integer 1 results in  
`0.0 + 0.7950600976206501im`

Using the float 1.0 results in  
`0.0 - 0.7950600976206501im`

The sign of the imaginary component is flipped.

---

<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: [August 14, 2025, 9:31pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/4 "2025-08-14T21:31:51Z")

</div>

> [@jogama](#):
>
> The sign of the imaginary component is flipped.

Is it? They look the same to me.

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [August 14, 2025, 9:33pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/5 "2025-08-14T21:33:23Z")

</div>

Your simplified example doesn’t show what you want but the real one ultimately is a question of floating point being able to represent both positive and negative zeroes, whereas integers can’t.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 14, 2025, 9:34pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/6 "2025-08-14T21:34:12Z")

</div>

> [@jogama](#):
>
> I’m curious as to why the results are different. Might anyone provide some insight into this?

It’s taking a different branch cut of the square root because floating-point numbers have a signed zero but integers do not.

In particular, notice:

```julia-auto
julia> -(1+0im) # Complex{Int}
-1 + 0im

julia> -(1.0+0im) # Complex{Float64}
-1.0 - 0.0im

```

Using `1.0+0im` causes both real and imaginary parts to be promoted to `Float64`, i.e. it is equivalent to `1.0+0.0im`. Then, negating it flips the sign of _both_ parts, because floating point numbers keep track of a sign bit for `±0.0`.

In most calculations, the sign bit of zero doesn’t matter, but it causes `sqrt` to choose a different branch cut for the square root of negative real numbers:

```julia-auto
julia> sqrt(-1.0 + 0.0im)
0.0 + 1.0im

julia> sqrt(-1.0 - 0.0im)
0.0 - 1.0im

```

This is not specific to Julia — it is completely standardized by IEEE floating-point arithmetic. See also the famous article:

- W. Kahan, [Branch cuts for complex elementary functions; or, Much ado about nothing’s sign bit](https://people.freebsd.org/~das/kahan86branch.pdf), _Proc. Joint IMA/SIAM Conf. on the State of the Art in Numerical Analysis_, pp. 165-211 (1987).

---

<div class="post-metadata">

### Author: ![jogama](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jogama/32/49842_2.png) [@jogama](https://discourse.julialang.org/u/jogama)
#### Post date: [August 14, 2025, 9:36pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/7 "2025-08-14T21:36:08Z")

</div>

Thank you, I completely forgot that negative zero exists in floating point. That does clear it up for me.

---

<div class="post-metadata">

### Author: ![jogama](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jogama/32/49842_2.png) [@jogama](https://discourse.julialang.org/u/jogama)
#### Post date: [August 14, 2025, 9:38pm UTC](https://discourse.julialang.org/t/different-results-when-using-1-and-1-0-in-expression/131617/8 "2025-08-14T21:38:19Z")

</div>

Thank you for the article! I’ll take a look. I somehow forgot about negative zero in floats, and had I remembered, I’m not sure I’d have made the connection to what I was reading.

Thank you all for replying so quickly.
