Home > Community > Forums > PCB SKILL > Comparing floating point numbers

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Comparing floating point numbers 

Last post Thu, May 18 2006 1:30 PM by archive. 1 replies.
Started by archive 18 May 2006 01:30 PM. Topic has 1 replies and 1440 views
Page 1 of 1 (2 items)
Sort Posts:
  • Thu, May 18 2006 1:30 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    Comparing floating point numbers Reply

    Unexpected results can occur when checking two floating point numbers for equality.
    For example:
    a = 0.1
    b = 0.3 / 3
    a == b returns nil.

    This behaviour is due to the IEEE floating point implementation and is explained well in: http://sourcelink.cadence.com/docs/db/kdb/2004/Dec/11162336.html

    You can use the following function to test for equality of two floating point numbers:
    defun( feq (f1, f2), abs(f1 - f2) < 0.00001

    Cheers Dave.


    Originally posted in cdnusers.org by Dave Elder
    • Post Points: 0
  • Thu, May 18 2006 2:20 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    RE: Comparing floating point numbers Reply


    In Allegro you can use axlGeoEqual(a b)


    Originally posted in cdnusers.org by fxf
    • Post Points: 0
Page 1 of 1 (2 items)
Sort Posts:
Started by archive at 18 May 2006 01:30 PM. Topic has 1 replies.