[erlang-questions] Floating point comparison for tests

Richard A. O'Keefe ok@REDACTED
Thu Aug 14 02:33:08 CEST 2008


I've lost the messages that this is a reply to, sorry.

This University has been involved in the Programming Contests for quite
a while, and I've designed some of the NZPC and one or two of the SPPC
problems.  As support for the programming contests, I wrote a program
that can compare a team's output file with a model answer.  Look at
http://www.cs.otago.ac.nz/staffpriv/ok/software.htm; it's the 'pcfpcmp'
item.

Quoting the documentation, it may have to match
	a floating point number that is in the specified
         interval.  An interval can be
             [ <range> ]     {x | a <= x <= z}
             [ <range> )     {x | a <= x <  z}
             ( <range> )     {x | a <  x <  z}
             ( <range> ]     {x | a <  x <= z}
         where a range can be
             L,U             a = L, z = U
             M*R             a = min(M/R,M*R), z = max(M/R,M*R)
             M+D             a = M-D, z = M+D

There are in fact times when you might want to make a distinction
between (0,1) and [0,1] and so on, despite what some people will
tell you about floating point numbers and equality.  (An exact 0
may in some cases mean exact disaster, so you may want to check
for it...)  Certainly the idea of checking anything involving
random number generation by offering a tiny epsilon is not in
general a sensible one.




--
If stupidity were a crime, who'd 'scape hanging?










More information about the erlang-questions mailing list