diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-01-05 16:36:56 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-01-05 16:36:56 +0000 |
commit | 4887a05481e143bfc4796230605d0a9ff7f2cb5a (patch) | |
tree | 495dce9e5a774e6826fa09f2651ae3c8c546822d /misc/pascal/tests/src/501-unit-cosine.pas | |
parent | 9684605c30d1f7f2f7120d8c1b5645e7ca4eb54f (diff) | |
download | nuttx-4887a05481e143bfc4796230605d0a9ff7f2cb5a.tar.gz nuttx-4887a05481e143bfc4796230605d0a9ff7f2cb5a.tar.bz2 nuttx-4887a05481e143bfc4796230605d0a9ff7f2cb5a.zip |
Pascal Tests
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@504 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'misc/pascal/tests/src/501-unit-cosine.pas')
-rw-r--r-- | misc/pascal/tests/src/501-unit-cosine.pas | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/misc/pascal/tests/src/501-unit-cosine.pas b/misc/pascal/tests/src/501-unit-cosine.pas new file mode 100644 index 000000000..5f79be4a2 --- /dev/null +++ b/misc/pascal/tests/src/501-unit-cosine.pas @@ -0,0 +1,36 @@ +{ Compute the cosine using the expansion: + cos(x) = 1 - x**2/(2*1) + x**4/(4*3*2*1) - ... + This file verifies a simple unit that exports one function. +} + +unit MyCosineUnit; + +interface + +function mycosine(x : real) : real; + +implementation + +function mycosine(x : real) : real; +const + eps = 1e-14; + +var + sx, s, t : real; + i, k : integer; + +begin + t := 1; + k := 0; + s := 1; + sx := sqr(x); + while abs(t) > eps*abs(s) do + begin + k := k + 2; + t := -t * sx / (k * (k - 1)); + s := s + t; + end; + mycosine := s +end; { mycosine } +end. + |