Approximate equality: Difference between revisions

Line 699:
===Using decimal library===
Uses tcllib's decimal library. Using a tolerance of 9 significant digits.
<lang Tcl>catch {namespace delete test_almost_equaltest_almost_equal_decimal} ;# Start with a clean namespace
 
namespace eval test_almost_equal_decimal {
Line 746:
</pre>
===Using string manipulation===
<lang Tcl>catch {namespace delete test_almost_equaltest_almost_equal_string} ;# Start with a clean namespace
 
namespace eval test_almost_equal_string {
Line 754:
proc isClose {a b {prec 9}} {
proc toCoeff {n prec} {
set repr 40 ;# Chosen to be arbitrarily large to handle most cases
set long [format %0.${repr}f $n] ;# Take out of scientific notation
set map [string map {. 0} $long] ;# Remove decimal point
Anonymous user