1#! /bin/csh -f 2# 3# this tests if C rounds the return value to single precision in 4# functions of type float. (see sec. 9.10 of C ref. manual). 5# 6cat << 'EOT' >! /tmp/test_fltc.c 7float temp; 8 9float f1_(arg1,arg2) 10float *arg1, *arg2; 11{ 12 /* force float by storing in global */ 13 temp = *arg1 / *arg2; 14 return temp; 15} 16 17float f2_(arg1,arg2) 18float *arg1, *arg2; 19{ 20 /* should round since function is type float */ 21 return *arg1 / *arg2; 22} 23 24 25float f3_(arg1,arg2) 26float *arg1, *arg2; 27{ 28 /* use a cast to try to force rounding */ 29 return ((float) (*arg1 / *arg2)); 30} 31 32'EOT' 33cat << 'EOT' >! /tmp/test_fltf.f 34 integer f2ok, f3ok 35 data f2ok/0/, f3ok/0/ 36 37 do 20 i = 1,10 38 do 10 j = 1,10 39 x = 0.1d0*i 40 y = 0.1d0*j 41 temp = f1(x,y) 42 if( f2(x,y).eq.temp) f2ok = f2ok + 1 43 if( f3(x,y).eq.temp) f3ok = f3ok + 1 4410 continue 4520 continue 46 print *, "out of 100 tries, f2 was ok", f2ok, "times" 47 print *, "out of 100 tries, f3 was ok", f3ok, "times" 48 end 49'EOT' 50pushd /tmp 51f77 test_fltc.c test_fltf.f -o test_flt 52test_flt 53