Skip to content

Instantly share code, notes, and snippets.

@YujiSODE
Last active November 10, 2018 10:15
Show Gist options
  • Save YujiSODE/ad3ab35235b1648c9f8e08f6a35e8439 to your computer and use it in GitHub Desktop.
Save YujiSODE/ad3ab35235b1648c9f8e08f6a35e8439 to your computer and use it in GitHub Desktop.
Additional mathematical method that returns sum of given array for Math object; This is implementation of "lSum.tcl" in JavaScript
/* lSum
* lSum.js
* ===================================================================
* Copyright (c) 2018 Yuji SODE <yuji.sode@gmail.com>
* These codes are free. You can redistribute and/or modify these codes.
* ===================================================================
* Additional mathematical method that returns sum of given array for Math object
* This is implementation of "lSum.tcl" in JavaScript
* [References]
* - Sode, Y. 2018. lSum.tcl; https://gist.github.com/YujiSODE/1f9a4e2729212691972b196a76ba9bd0
* - Iri, M., and Fujino., Y. 1985. Suchi keisan no joshiki (in Japanese). Kyoritsu Shuppan Co., Ltd.; ISBN 978-4-320-01343-8
*===================================================================
*/
//additional mathematical method that returns sum of given array for Math object
Math.lSum=function(Arr){
// - Arr: a numerical array
var n=Arr.length,i=0,
S=0.0,R=0.0,T=0.0;
while(i<n){
R+=+Arr[i];
T=S;
S+=R;
T=S-T;
R-=T;
i+=1;
}
return S;
};
/*=== lSum.js (Yuji SODE, 2018): https://gist.github.com/YujiSODE/ad3ab35235b1648c9f8e08f6a35e8439 ===
* This is implementation of "lSum.tcl" in JavaScript
* [References]
* - Sode, Y. 2018. lSum.tcl; https://gist.github.com/YujiSODE/1f9a4e2729212691972b196a76ba9bd0
* - Iri, M., and Fujino., Y. 1985. Suchi keisan no joshiki (in Japanese). Kyoritsu Shuppan Co., Ltd.; ISBN 978-4-320-01343-8
*/
Math.lSum=function(Arr){var n=Arr.length,i=0,S=0.0,R=0.0,T=0.0;while(i<n){R+=+Arr[i];T=S;S+=R;T=S-T;R-=T;i+=1;}return S;};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment