# Casting std::atomic\<float\>\* variables

**URL:** <https://forum.juce.com/t/casting-std-atomic-float-variables/37790>\
**Category:** General JUCE discussion\
**Created:** [February 26, 2020, 11:28pm UTC](https://forum.juce.com/t/casting-std-atomic-float-variables/37790 "2020-02-26T23:28:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gazayas](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gazayas/32/7957_2.png) [@gazayas](https://forum.juce.com/u/gazayas)\
**Post date:** [February 26, 2020, 11:28pm UTC](https://forum.juce.com/t/casting-std-atomic-float-variables/37790/1 "2020-02-26T23:28:36Z")

</div>

Hello, I’m still new to JUCE, so please forgive me if this isn’t a good question!

I’m running on v5.4.7 and tried compiling a v5.4.6 project recently. There were some `float*` variables assigned from `getRawParameter()` and it threw me an error about the floats, so I changed them to `std::atomic<float>*`.

I saw this commit as well:

> <https://github.com/WeAreROLI/JUCE/commit/70ddcd16e60d2dc97f0bdae576528806d71c9090>

The problem is, there was somewhere else in the code where the developer tried to cast it to an int with `roundToInt()` from the JUCE core (the problem was specifically with line 478 of `juce_MathsFunctions.h`) saying something about not being able to cast it?

Can an atomic float be cast to anything? Should it be? How should I handle it if I want to make it into an int?

Sorry if this doesn’t make sense, or if it’s a simple mistake!

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [February 26, 2020, 11:59pm UTC](https://forum.juce.com/t/casting-std-atomic-float-variables/37790/2 "2020-02-26T23:59:31Z")

</div>

Just to clarify terminology, `roundToInt()` is not a cast, it is a function that rounds a `float` to an `int`, and returns an `int`. Having said that, `roundToInt (yourAtomicFloat.load());` should do the trick.

---

<div class="post-metadata">

**Author:** ![gazayas](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gazayas/32/7957_2.png) [@gazayas](https://forum.juce.com/u/gazayas)\
**Post date:** [February 27, 2020, 12:20am UTC](https://forum.juce.com/t/casting-std-atomic-float-variables/37790/3 "2020-02-27T00:20:54Z")

</div>

I see, thank you for the clarification! I’ll see if I can try using the `load` function later today and post back with results.

Thanks again!

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [February 27, 2020, 9:22am UTC](https://forum.juce.com/t/casting-std-atomic-float-variables/37790/4 "2020-02-27T09:22:47Z")

</div>

N.B. if you are talking about the return value of getRawParameterValue, since it is a pointer to the std::atomic, simply use `->` instead of `.`  
And consider keeping the pointer as member variable, that saves you the lookup each processBlock() call.

---

<div class="post-metadata">

**Author:** ![gazayas](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gazayas/32/7957_2.png) [@gazayas](https://forum.juce.com/u/gazayas)\
**Post date:** [February 27, 2020, 10:50am UTC](https://forum.juce.com/t/casting-std-atomic-float-variables/37790/5 "2020-02-27T10:50:16Z")

</div>

Hello Daniel, thank you! I went with `var.atomicFloat->load();` and that worked!  
Thank you for the member variable advice too.

---

<div class="post-metadata">

**Author:** ![gazayas](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gazayas/32/7957_2.png) [@gazayas](https://forum.juce.com/u/gazayas)\
**Post date:** [February 27, 2020, 10:51am UTC](https://forum.juce.com/t/casting-std-atomic-float-variables/37790/6 "2020-02-27T10:51:32Z")

</div>

Thank you for the advice! I used the `load()` function and that worked out just fine!
