math::fuzzy - Fuzzy comparison of floating-point numbers
TABLE OF CONTENTS
SYNOPSIS
DESCRIPTION
PROCEDURES
TEST CASES
REFERENCES
BUGS, IDEAS, FEEDBACK
KEYWORDS
package require Tcl ?8.3?
package require math::fuzzy ?0.2?
The package Fuzzy is meant to solve common problems with floating-point numbers in a systematic way:
The Fuzzy package is meant to help sorting out this type of problems by defining "fuzzy" comparison procedures for floating-point numbers. It does so by allowing for a small margin that is determined automatically - the margin is three times the "epsilon" value, that is three times the smallest number eps such that 1.0 and 1.0+$eps canbe distinguished. In Tcl, which uses double precision floating-point numbers, this is typically 1.1e-16.
Effectively the package provides the following procedures:
if { [teq $x $y] } { puts "x == y" } if { [tne $x $y] } { puts "x != y" } if { [tge $x $y] } { puts "x >= y" } if { [tgt $x $y] } { puts "x > y" } if { [tlt $x $y] } { puts "x < y" } if { [tle $x $y] } { puts "x <= y" } set fx [tfloor $x] set fc [tceil $x] set rounded [tround $x] set roundn [troundn $x $nodigits] |
The problems that can occur with floating-point numbers are illustrated by the test cases in the file "fuzzy.test":
Note that besides the Tcl-only package, there is also a C-based version.
Original implementation in Fortran by dr. H.D. Knoble (Penn State University).
P. E. Hagerty, "More on Fuzzy Floor and Ceiling," APL QUOTE QUAD 8(4):20-24, June 1978. Note that TFLOOR=FL5 took five years of refereed evolution (publication).
L. M. Breed, "Definitions for Fuzzy Floor and Ceiling", APL QUOTE QUAD 8(3):16-23, March 1978.
D. Knuth, Art of Computer Programming, Vol. 1, Problem 1.2.4-5.
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category math :: fuzzy of the Tcllib SF Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.
floating-point, math, rounding