# Comparing floating point with == or != is unsafe

**URL:** <https://forum.juce.com/t/comparing-floating-point-with-or-is-unsafe/56839>\
**Category:** General JUCE discussion\
**Created:** [June 28, 2023, 4:18pm UTC](https://forum.juce.com/t/comparing-floating-point-with-or-is-unsafe/56839 "2023-06-28T16:18:31Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![kcoul](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kcoul](https://forum.juce.com/u/kcoul)\
**Post date:** [July 12, 2023, 6:18pm UTC](https://forum.juce.com/t/comparing-floating-point-with-or-is-unsafe/56839/8 "2023-07-12T18:18:09Z")

</div>

Yeah, from reading the first article I think that’s why a ULP-based approximatelyEqual method argument in JUCE would be useful, though I guess one could argue that the “disadvantage” discussed in the article might present itself if developers didn’t understand how to use it properly. Used properly however, it could allow for some very powerful approaches to signal output analysis, especially if you could leverage higher precision comparisons in double-based and long double-based signal computations vs float. It might make it hard to provide a single appropriate ULP default that would make sense for all templated types however.

> [@approximatelyEqual rationale](https://forum.juce.com/t/approximatelyequal-rationale/56674/3):
>
> It might be nice to have a tuneable overload of approximatelyEqual() for things like autocorrelation with error margins, I think that’s what the ULP argument offers in this example: [https://en.cppreference.com/w/cpp/types/numeric\_limits/epsilon](https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon)

---

_[View the full topic](https://forum.juce.com/t/comparing-floating-point-with-or-is-unsafe/56839)._
