Collection of Tcl tools (v0.1)

::tcl::mathfuncTop, Main, Index

CommandsTop, Main, Index

divll [::tcl::mathfunc]Top, Main, Index

Divides each element of the list1 to each element of list2

divll list1 list2
Parameters
list1First list of values.
list2Second list of values.
Return value

list

proc ::tcl::mathfunc::divll {list1 list2} {

    # Divides each element of the list1 to each element of list2
    #  list1 - first list of values
    #  list2 - second list of values
    # Returns: list
    set result [list]
    if {[llength $list1]!=[llength $list2]} {
        return -code error "Lengths of the input lists '[llength $list1]' and '[llength $list2]' are not equal"
    }
    foreach value1 $list1 value2 $list2 {
        lappend result [= {double($value1)/double($value2)}]
    }
    return $result
}

divlsc [::tcl::mathfunc]Top, Main, Index

Divides each element of the list to scalar value

divlsc list scalar
Parameters
listList of values.
scalarScalar divider.
Return value

list

proc ::tcl::mathfunc::divlsc {list scalar} {

    # Divides each element of the list to scalar value
    #  list - list of values
    #  scalar - scalar divider
    # Returns: list
    set result [list]
    foreach value $list {
        lappend result [= {double($value)/double($scalar)}]
    }
    return $result
}

exactone [::tcl::mathfunc]Top, Main, Index

Calculates boolean function that returns true if only exactly one element is true

exactone ?args?
Parameters
argsBoolean values.
Return value

boolean

proc ::tcl::mathfunc::exactone {args} {

    # Calculates boolean function that returns `true` if only exactly one element is `true`
    #  args - boolean values
    # Returns: boolean
    set first false
    foreach arg $args {
        if {$first && $arg} {
            return false
        }
        if {$arg} {
            set first true
        }
    }
    if {$first} {
        return true
    } else {
        return false
    }
}

li [::tcl::mathfunc]Top, Main, Index

Wraps lindex command into expr function

li list index ?args?
Parameters
listNot documented.
indexNot documented.
proc ::tcl::mathfunc::li {list index args} {

    # Wraps `lindex` command into expr function
    ::lindex $list $index {*}$args
}

lindex [::tcl::mathfunc]Top, Main, Index

Wraps lindex command into expr function

lindex list index ?args?
Parameters
listNot documented.
indexNot documented.
proc ::tcl::mathfunc::lindex {list index args} {

    # Wraps `lindex` command into expr function
    ::lindex $list $index {*}$args
}

llength [::tcl::mathfunc]Top, Main, Index

Wraps llength command into expr function

llength list
Parameters
listNot documented.
proc ::tcl::mathfunc::llength {list} {

    # Wraps `llength` command into expr function
    ::llength $list
}

logb [::tcl::mathfunc]Top, Main, Index

Implements logarithm function with arbitary base

logb value base
Parameters
valueValue to calculate the logarithm from.
baseLogarithm base.
Return value

value of logarithm

proc ::tcl::mathfunc::logb {value base} {

    # Implements logarithm function with arbitary base
    #  value - value to calculate the logarithm from
    #  base - logarithm base
    # Returns: value of logarithm
    return [= {log($value)/double(log($base))}]
}

lrange [::tcl::mathfunc]Top, Main, Index

Wraps lrange command into expr function

lrange list first last
Parameters
listNot documented.
firstNot documented.
lastNot documented.
proc ::tcl::mathfunc::lrange {list first last} {

    # Wraps `lrange` command into expr function
    ::lrange $list $first $last
}

maxl [::tcl::mathfunc]Top, Main, Index

Wraps ::tcl::mathfunc::max command to accept single list instead of expanded one

maxl list
Parameters
listNot documented.
proc ::tcl::mathfunc::maxl {list} {

    # Wraps ::tcl::mathfunc::max command to accept single list instead of expanded one
    return [::tcl::mathfunc::max {*}$list]
}

minl [::tcl::mathfunc]Top, Main, Index

Wraps ::tcl::mathfunc::min command to accept single list instead of expanded one

minl list
Parameters
listNot documented.
proc ::tcl::mathfunc::minl {list} {

    # Wraps ::tcl::mathfunc::min command to accept single list instead of expanded one
    return [::tcl::mathfunc::min {*}$list]
}

mulll [::tcl::mathfunc]Top, Main, Index

Multiplies each element of the list1 to each element of list2

mulll list1 list2
Parameters
list1First list of values.
list2Second list of values.
Return value

list

proc ::tcl::mathfunc::mulll {list1 list2} {

    # Multiplies each element of the list1 to each element of list2
    #  list1 - first list of values
    #  list2 - second list of values
    # Returns: list
    set result [list]
    if {[llength $list1]!=[llength $list2]} {
        return -code error "Lengths of the input lists '[llength $list1]' and '[llength $list2]' are not equal"
    }
    foreach value1 $list1 value2 $list2 {
        lappend result [= {double($value1*$value2)}]
    }
    return $result
}

mullsc [::tcl::mathfunc]Top, Main, Index

Multiplies each element of the list to scalar value

mullsc list scalar
Parameters
listList of values.
scalarScalar multiplier.
Return value

list

proc ::tcl::mathfunc::mullsc {list scalar} {

    # Multiplies each element of the list to scalar value
    #  list - list of values
    #  scalar - scalar multiplier
    # Returns: list
    set result [list]
    foreach value $list {
        lappend result [= {double($scalar*$value)}]
    }
    return $result
}

powll [::tcl::mathfunc]Top, Main, Index

Exponentiates each element of the list1 in each element of list2

powll list1 list2
Parameters
list1First list of values.
list2Second list of values.
Return value

list

proc ::tcl::mathfunc::powll {list1 list2} {

    # Exponentiates each element of the list1 in each element of list2
    #  list1 - first list of values
    #  list2 - second list of values
    # Returns: list
    set result [list]
    if {[llength $list1]!=[llength $list2]} {
        return -code error "Lengths of the input lists '[llength $list1]' and '[llength $list2]' are not equal"
    }
    foreach value1 $list1 value2 $list2 {
        lappend result [= {pow($value1,$value2)}]
    }
    return $result
}

powlsc [::tcl::mathfunc]Top, Main, Index

Exponentiates each element of the list in scalar value

powlsc list scalar
Parameters
listList of values.
scalarScalar power value.
Return value

list

proc ::tcl::mathfunc::powlsc {list scalar} {

    # Exponentiates each element of the list in scalar value
    #  list - list of values
    #  scalar - scalar power value
    # Returns: list
    set result [list]
    foreach value $list {
        lappend result [= {pow($value,$scalar)}]
    }
    return $result
}

subll [::tcl::mathfunc]Top, Main, Index

Subtracts each element of the list2 from each element of list1

subll list1 list2
Parameters
list1First list of values.
list2Second list of values.
Return value

list

proc ::tcl::mathfunc::subll {list1 list2} {

    # Subtracts each element of the list2 from each element of list1
    #  list1 - first list of values
    #  list2 - second list of values
    # Returns: list
    set result [list]
    if {[llength $list1]!=[llength $list2]} {
        return -code error "Lengths of the input lists '[llength $list1]' and '[llength $list2]' are not equal"
    }
    foreach value1 $list1 value2 $list2 {
        lappend result [= {double($value1-$value2)}]
    }
    return $result
}

sublsc [::tcl::mathfunc]Top, Main, Index

Subtracts scalar value from each element of the list

sublsc list scalar
Parameters
listList of values.
scalarScalar value to subtract.
Return value

list

proc ::tcl::mathfunc::sublsc {list scalar} {

    # Subtracts scalar value from each element of the list
    #  list - list of values
    #  scalar - scalar value to subtract
    # Returns: list
    set result [list]
    foreach value $list {
        lappend result [= {double($value-$scalar)}]
    }
    return $result
}

sumll [::tcl::mathfunc]Top, Main, Index

Sums each element of the list1 with each element of list2

sumll list1 list2
Parameters
list1First list of values.
list2Second list of values.
Return value

list

proc ::tcl::mathfunc::sumll {list1 list2} {

    # Sums each element of the list1 with each element of list2
    #  list1 - first list of values
    #  list2 - second list of values
    # Returns: list
    set result [list]
    if {[llength $list1]!=[llength $list2]} {
        return -code error "Lengths of the input lists '[llength $list1]' and '[llength $list2]' are not equal"
    }
    foreach value1 $list1 value2 $list2 {
        lappend result [= {double($value1+$value2)}]
    }
    return $result
}

sumlsc [::tcl::mathfunc]Top, Main, Index

Adds scalar value to each element of the list

sumlsc list scalar
Parameters
listList of values.
scalarScalar value to add.
Return value

list

proc ::tcl::mathfunc::sumlsc {list scalar} {

    # Adds scalar value to each element of the list
    #  list - list of values
    #  scalar - scalar value to add
    # Returns: list
    set result [list]
    foreach value $list {
        lappend result [= {double($scalar+$value)}]
    }
    return $result
}