File: avg.ft

package info (click to toggle)
fudgit 2.42-6
  • links: PTS
  • area: non-free
  • in suites: potato, woody
  • size: 2,468 kB
  • ctags: 2,375
  • sloc: ansic: 27,729; makefile: 793; yacc: 724; lex: 102; asm: 29; fortran: 15
file content (28 lines) | stat: -rw-r--r-- 422 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# This file is an example on how one can define a function
# computing the average of a vector

# Play safe!
free @all

cmode
    func avg(X) {
        auto i,x

        for (x=0,i=1;i<=data;i++) {
            x += X[i]
        }
        return(x/data)
    }
fmode
# The following is equivalent
cmode
	func avg2(X) {
		auto x, i=1		# By default x is 0

		while (i <= data) {
			x += X[i++]
		}
		return (x/data)
	}
fmode