Last active
November 14, 2018 16:56
-
-
Save YujiSODE/1f9a4e2729212691972b196a76ba9bd0 to your computer and use it in GitHub Desktop.
Additional mathematical functions for Tcl expressions: function that returns sum of given list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lSum.tcl | |
#Copyright (c) 2018 Yuji SODE | |
#These codes are free. You can redistribute and/or modify these codes. | |
#Additional mathematical functions for Tcl expressions | |
# - lSum(list): function that returns sum of given list | |
# - $list: a numerical list | |
#Reference | |
#Iri, M., and Fujino., Y. 1985. Suchi keisan no joshiki (in Japanese). Kyoritsu Shuppan Co., Ltd. | |
#ISBN 978-4-320-01343-8 | |
proc ::tcl::mathfunc::lSum {list} { | |
namespace path {::tcl::mathop}; | |
set S 0.0; | |
set R 0.0; | |
set T 0.0; | |
foreach e $list { | |
set R [+ $R [expr double($e)]]; | |
set T $S; | |
set S [+ $S $R]; | |
set T [+ $S [expr {-$T}]]; | |
set R [+ $R [expr {-$T}]]; | |
}; | |
return $S; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=== lSum.tcl (Yuji SODE, 2018): https://gist.github.com/YujiSODE/1f9a4e2729212691972b196a76ba9bd0 === | |
#Additional mathematical functions for Tcl expressions | |
# [References] | |
# - Iri, M., and Fujino., Y. 1985. Suchi keisan no joshiki (in Japanese). Kyoritsu Shuppan Co., Ltd.; ISBN 978-4-320-01343-8 | |
proc ::tcl::mathfunc::lSum {list} {namespace path {::tcl::mathop};set S 0.0;set R 0.0;set T 0.0;foreach e $list {set R [+ $R [expr double($e)]];set T $S;set S [+ $S $R];set T [+ $S [expr {-$T}]];set R [+ $R [expr {-$T}]];};return $S;}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment