Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It also doesn't feel right to me when I learned it for the first time. But if you know that "=" means "almost equal" when doing float comparision, it is very convenient in practical use. For example, if we want to compare two float variables. In Red:

  if float-1 = float-2 [
      ; do something
  ]
In other languages:

  if (float-1 - float-2) < EPS {
      // do something
  }
Obviously, Red's way is more natural and readable. :)


Choosing the epsilon requires numerical analyis expertise or lucky cargo-cuting: https://randomascii.wordpress.com/2012/02/25/comparing-float...


Thank you for reminding us about those great articles! We were using a Ulp-based method only, but Qtxie proceeded with some improvements [1] for close to zero values, as suggested in the article. Thanks again. :-)

[1] https://github.com/red/red/pull/986




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: