Skip to content

Instantly share code, notes, and snippets.

@YujiSODE
Last active November 14, 2018 16:56
Show Gist options
  • Save YujiSODE/1f9a4e2729212691972b196a76ba9bd0 to your computer and use it in GitHub Desktop.
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
#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;
};
#=== 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