summaryrefslogtreecommitdiff
path: root/lib/lib/Math.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib/Math.tcl')
-rw-r--r--[-rwxr-xr-x]lib/lib/Math.tcl49
1 files changed, 31 insertions, 18 deletions
diff --git a/lib/lib/Math.tcl b/lib/lib/Math.tcl
index bf2be0d..af5e0ae 100755..100644
--- a/lib/lib/Math.tcl
+++ b/lib/lib/Math.tcl
@@ -1,7 +1,7 @@
#!/usr/bin/tclsh
############################################################################
-# Copyright (C) 2007-2009 by Martin Ošmera #
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
@@ -20,6 +20,11 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+
+# >>> File inclusion guard
+if { ! [ info exists _MATH_TCL ] } {
+set _MATH_TCL _
+# <<< File inclusion guard
# --------------------------------------------------------------------------
# DESCRIPTION
# Primarily implements convertions between numeric systems and angle units.
@@ -51,7 +56,7 @@
# puts [ NumSystem::bin2hex 1111.01 ] ;# --> F.4
# puts [ NumSystem::bin2dec 1111.01 ] ;# --> 15.25
# puts [ NumSystem::bin2oct 1111.01 ] ;# --> 17.2
- #
+ #
# puts [ NumSystem::ascii2dec @ ] ;# --> 64
# puts [ NumSystem::ascii2bin @ ] ;# --> 01000000
#
@@ -273,7 +278,7 @@ namespace eval NumSystem {
if {[regexp {\.\d+$} $number frac]} {
set frac [string range $frac 1 end]
set nofrac 0
- } {
+ } else {
set frac {}
set nofrac 1
}
@@ -334,7 +339,7 @@ namespace eval NumSystem {
if {$result != {}} {
return [dec2bin $result]
}
-
+
return $result
}
@@ -348,7 +353,7 @@ namespace eval NumSystem {
}
set result {}
scan $number {%c} result
-
+
return $result
}
@@ -363,7 +368,7 @@ namespace eval NumSystem {
proc asserthex {number} {
if {![ishex $number]} {
error "asserthex: Excepted hexadecimal value but got \"$number\""
- } {
+ } else {
return 1
}
}
@@ -375,7 +380,7 @@ namespace eval NumSystem {
proc assertdec {number} {
if {![isdec $number]} {
error "assertdec: Excepted decimal value but got \"$number\""
- } {
+ } else {
return 1
}
}
@@ -387,7 +392,7 @@ namespace eval NumSystem {
proc assertoct {number} {
if {![isoct $number]} {
error "assertoct: Excepted octal value but got \"$number\""
- } {
+ } else {
return 1
}
}
@@ -399,7 +404,7 @@ namespace eval NumSystem {
proc assertbin {number} {
if {![isbin $number]} {
error "assertbin: Excepted binary value but got \"$number\""
- } {
+ } else {
return 1
}
}
@@ -466,7 +471,7 @@ namespace eval NumSystem {
if {$base == 8} {
assertoct $number
set char_len 3
- } {
+ } else {
asserthex $number
set char_len 4
}
@@ -478,7 +483,7 @@ namespace eval NumSystem {
if {[regexp {\.[^\.]+$} $number frac]} {
set frac [string range $frac 1 end]
set nofrac 0
- } {
+ } else {
set frac {}
set nofrac 1
}
@@ -486,7 +491,7 @@ namespace eval NumSystem {
# compute int. part
if {$base == 8} {
set int [expr "0$int"]
- } {
+ } else {
set int [expr "0x$int"]
}
@@ -513,7 +518,7 @@ namespace eval NumSystem {
if {$base == 8} {
set v3 $v0
- } {
+ } else {
set v3 [expr {$v0 / 2}]
}
set v2 [expr {$v3 / 2}]
@@ -569,7 +574,7 @@ namespace eval NumSystem {
set mod_1 2
set padding {}
set convCmd {oct_to_bin}
- } {
+ } else {
set modulo 4
set mod_1 3
set padding {0}
@@ -581,7 +586,7 @@ namespace eval NumSystem {
if {[regexp {\.\d+$} $number frac]} {
set frac [string range $frac 1 end]
set nofrac 0
- } {
+ } else {
set frac {}
set nofrac 1
}
@@ -670,7 +675,7 @@ namespace eval NumSystem {
if {[regexp {\.\d+$} $number frac]} {
set frac [string range $frac 1 end]
set nofrac 0
- } {
+ } else {
set frac {}
set nofrac 1
}
@@ -817,7 +822,7 @@ namespace eval NumSystem {
return 0
}
- # 3rd condition (dot must not be at the begining or end)
+ # 3rd condition (dot must not be at the beginning or end)
if {[regexp {^\.} $number]} {return 0}
if {[regexp {\.$} $number]} {return 0}
@@ -940,7 +945,11 @@ namespace eval Angle {
}
# is negative or something else ?
- if {$angle < 0} {set minus 1} {set minus 0}
+ if {$angle < 0} {
+ set minus 1
+ } else {
+ set minus 0
+ }
# adjust angle value
set angle [expr {$angle / $base}]
@@ -952,3 +961,7 @@ namespace eval Angle {
return $angle
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard