# Float is an Inf and I can't use && to assign it a new value

**URL:** <https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773>\
**Category:** New to Julia\
**Created:** [September 4, 2022, 9:13pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773 "2022-09-04T21:13:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [September 4, 2022, 9:13pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/1 "2022-09-04T21:13:29Z")

</div>

I’m trying to use the short circuit conditional from [the julia docs](https://docs.julialang.org/en/v1/manual/control-flow/) and I have a sneaking feeling that this will correct a misapprehension of what is going on. My “thought” is that this should spot that sdmove is an Inf and change it to the number 999.99.

any help appreciated.

```julia
In the expression a && b, the subexpression b is only evaluated if a evaluates to true.

```

```julia
isinf(sdmove)
true

julia> isinf(sdmove) && sdmove = 999.99
ERROR: syntax: invalid assignment location "isinf(sdmove) && sdmove" around REPL[25]:1
Stacktrace:
 [1] top-level scope
   @ REPL[25]:1
julia> typeof(sdmove)
Float64

julia> typeof(999.99)
Float64

julia> 

```

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [September 4, 2022, 9:28pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/2 "2022-09-04T21:28:35Z")

</div>

Due to the relative priorities of infix operators `&&` and `=`, this is parsed as

```julia
(isinf(sdmove) && sdmove) = 999.99

```

instead of what you really meant:

```julia
isinf(sdmove) && (sdmove = 999.9)

```

You can use this last expression in order to explicitly set the correct order of operations.

  

_(Opinions on this may vary from one developer to another, but I personally tend to dislike short circuits in cases where the RHS is an assignment, precisely for that reason. But I do like short circuits like `isinf(sdmove) && break`, because they don’t suffer from the same need for explicit parentheses)_

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [September 4, 2022, 9:42pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/3 "2022-09-04T21:42:49Z")

</div>

@ffevotte you are a LEGEND. Worked like a champ. Thanks for taking the time. I’ll check out the infix operator precedence for future use. I’ll also give some HARD consideration to taking another coding approach.  
BUT I’m trying to stop this error happening. I PROMISE I’ll try though 🙂 thanks again.

```julia
┌ Error: ErrorException("Inf not allowed to be written in JSON spec")
└ @ Stipple /home/dave/.julia/packages/Stipple/qiTHA/src/Stipple.jl:889

```

Thanks again.  
theakson

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [September 4, 2022, 10:49pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/4 "2022-09-04T22:49:54Z")

</div>

If you do stick with a “sentinel” value consider something way outside the range of reasonable like the max possible float, or maybe 9.99e99

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [September 4, 2022, 11:00pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/5 "2022-09-04T23:00:21Z")

</div>

> [@dlakelan](#):
>
> like the max possible float

@anon69491625 In case you haven’t come across it, the preferred way is with ~~`typemax(typeof(sdmove))`~~ `floatmax(sdmove)`.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [September 4, 2022, 11:04pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/6 "2022-09-04T23:04:44Z")

</div>

> [@Jollywatt](#):
>
> `typemax(typeof(sdmove))`.

For floats this just returns Inf though.

Largest float other than inf is `floatmax(Float64)`

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [September 4, 2022, 11:44pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/7 "2022-09-04T23:44:17Z")

</div>

there’s something actually HHGG’esq about this 🙂

```julia
julia> isinf(sdmove) && typemax(typeof(sdmove))
Inf

```

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [September 4, 2022, 11:45pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/8 "2022-09-04T23:45:05Z")

</div>

excellent didn’t know about typemax() thanks @Jollywatt and for the heads up @dlakelan

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [September 4, 2022, 11:50pm UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/9 "2022-09-04T23:50:14Z")

</div>

The 999.99 was chosen as I’m using the WONDERFUL Stipple.jl and wanted something I can sort. Will certainly bear your advice in mind for later on “when” I get this working.  
thanks again

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [September 5, 2022, 12:28am UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/10 "2022-09-05T00:28:56Z")

</div>

I think this is a right of passage for everyone going from beginner to intermediate level of Julia and working with short circuiting. I went through a very similar headache a while ago.

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [September 5, 2022, 12:47am UTC](https://discourse.julialang.org/t/float-is-an-inf-and-i-cant-use-to-assign-it-a-new-value/86773/11 "2022-09-05T00:47:46Z")

</div>

hmm @affans my rite of passage seems to be reversed, I started knowing things and I seem to be devolving 🙂
