pgtap icon indicating copy to clipboard operation
pgtap copied to clipboard

Add function to test if value is approximately equal

Open jnasbyupgrade opened this issue 5 months ago • 1 comments
trafficstars

Sometimes you only care that a value is "reasonable" - that it's within an error range (for example, when working with floating point). In these cases it would be handy to have a set of comparison functions that allow you to specify an allowed error value. For example...

is_approximately( 10::real / 3, 3.333, 1e-2 )

internally, this would pass as long as 10::real / 3 was between 3.333 - 1e-2 and 3.333 + 1e-2.

Note that while you could do this with ranges (at least, for data types that have them), this is still more convenient than having to define the range correctly yourself.

The only thing I don't like about this idea is the name... is_approximately is pretty freaking long. :( Does anyone have other ideas? Note that we'd want a version of this for all the result-set functions as well (result_eq(), result_ne(), bag_eq(), etc).

jnasbyupgrade avatar Jun 09 '25 22:06 jnasbyupgrade

The Go assert package calls this assertion inDelta.

theory avatar Jun 10 '25 21:06 theory