Comparing jittery floats in XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ggorokhovsky
    New User
    • Oct 2008
    • 0

    Comparing jittery floats in XML

    What would be a way to flag as unimportant small differences (in the number sense) in the float values embedded as attribute values in an xml?

    For example
    <volume value="106401.4991181042" />
    could be "unimportantly" different from
    <volume value="106401.4991201881" /> because they are within 1e-4 of each other.


    Thank you,
    Gene Gorokhovsky
  • Michael Bulgrien
    Carpal Tunnel
    • Oct 2007
    • 1772

    #2
    Create a basic grammar rule using regular expressions.
    For example, the following regular expression could be used to define the decimal portion of a value:

    \.\d+"

    If you make the gammar element unimportant in your sessions settings tab, then differences in that portion of the value will be considered unimportant. To limit the characters to the last four digits, you could use something like this:

    \d{4}"

    You could create another grammar element like the following to ensure that numbers without decimal points are always considered to be important:

    "\d+"

    Or a grammar element like this to ensure that decimal values are important up through the first four digits:

    \.\d{1,4}

    Move grammar elements up or down in the list to determine their priority.
    BC v4.0.7 build 19761
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Comment

    Working...