Hi.
Here's one alternative:
#!/usr/bin/env tcsh
# @(#) s1 Demonstrate alternative for tcsh floating-point arithmetic.
echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version "=o" tcsh
echo
alias acalc 'awk "BEGIN{ print \!* }" '
# START RI LOOP
set RI_min = 10
set RI_max = 30
set RI_inc = 1
set RI = $RI_min
while ($RI <= $RI_max)
# @ PI=$RI / 10
set PI = `acalc $RI / 10`
# echo "PI = " $PI "g cm^-3"
# echo $RI
echo " RI = $RI, PI = " $PI "g cm^-3"
@ RI = $RI + $RI_inc
end
exit 0
producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
tcsh 6.14.00
RI = 10, PI = 1 g cm^-3
RI = 11, PI = 1.1 g cm^-3
RI = 12, PI = 1.2 g cm^-3
RI = 13, PI = 1.3 g cm^-3
RI = 14, PI = 1.4 g cm^-3
RI = 15, PI = 1.5 g cm^-3
RI = 16, PI = 1.6 g cm^-3
RI = 17, PI = 1.7 g cm^-3
RI = 18, PI = 1.8 g cm^-3
RI = 19, PI = 1.9 g cm^-3
RI = 20, PI = 2 g cm^-3
RI = 21, PI = 2.1 g cm^-3
RI = 22, PI = 2.2 g cm^-3
RI = 23, PI = 2.3 g cm^-3
RI = 24, PI = 2.4 g cm^-3
RI = 25, PI = 2.5 g cm^-3
RI = 26, PI = 2.6 g cm^-3
RI = 27, PI = 2.7 g cm^-3
RI = 28, PI = 2.8 g cm^-3
RI = 29, PI = 2.9 g cm^-3
RI = 30, PI = 3 g cm^-3
See Floating Point for a brief explanation of the alias.
Note that many people will advise you to avoid tcsh scripting. Using Bourne-shell relatives seems to work best for most projects. Here's an example of zsh illustrating built-in floating-point arithmetic (in later versions of ksh as well):
#!/usr/bin/env zsh
# @(#) s2 Demonstrate zsh floating-point arithmetic.
echo
set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) ksh
set -o nounset
echo
i=1
while (( i < 3.0 ))
do
print " i = $i"
(( i+=0.5 ))
done
exit 0
producing:
% ./s2
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
zsh 4.3.6
ksh 93s+
i = 1
i = 1.5
i = 2.
i = 2.5
Best wishes ... cheers, drl