Artifact
817b7fd1d205b0a8ab1912a2929765a1a2b1cc7119dea31522e713d629ec6a72:
Attachment "math-decimal--example.tcl.patch" to
ticket [45fe064cf2]
added by
ricardo-andre
2017-08-27 21:51:16.
(unpublished)
--- math-decimal--example.tcl 2016-03-12 23:32:30.032885729 +0000
+++ math-decimal--example-new.tcl 2016-03-12 23:34:41.921577489 +0000
@@ -1,10 +1,10 @@
-package require decimal
+package require math::decimal
# Various operations on two numbers.
# We first convert them to decimal format.
set a [::math::decimal::fromstr 8.2]
set b [::math::decimal::fromstr .2]
-# Then we perform our operations. Here we multiply
-set c [::math::decimal::* $a $b]
+# Then we perform our operations. Here we add
+set c [::math::decimal::+ $a $b]
# Finally we convert back to string format for presentation to the user.
puts [::math::decimal::tostr $c] ; # => will output 8.4
# Other examples
@@ -13,6 +13,6 @@
set c [::math::decimal::- $a $b]
puts [::math::decimal::tostr $c] ; # => will output 8.0
# Why bother using this instead of simply expr?
-puts 8.399999999999999 ; # => will output 8.399999999999999
-puts 7.999999999999999 ; # => will output 7.999999999999999
+puts [expr 8.2+0.2] ; # => will output 8.399999999999999
+puts [expr 8.2-0.2] ; # => will output 7.999999999999999
# See http://speleotrove.com/decimal to learn more about why this happens.