[comp.os.msdos.programmer] TC vs mainframe

yding@unix.cis.pitt.edu (Yijun Ding ) (05/13/91)

Recently I have a program with small floatings. I find something works
on my TC but not on mainframe. The following code, log10() print
correctly on TC2.0. It is HUGE on unix, and 0 on VMS in University of
Pittsburgh. That is a surprise.

#include <math.h>
main()
{
  double a=1.12345e-40;
  printf("%lf %lf\n", a, log10(a));
} 

Any one can explain why?

bobmon@iuvax.cs.indiana.edu (RAMontante) (05/13/91)

yding@unix.cis.pitt.edu (Yijun Ding ) <127293@unix.cis.pitt.edu> :
| 
| #include <math.h>
| main()
| {
|   double a=1.12345e-40;
|   printf("%lf %lf\n", a, log10(a));
| } 

The gcc compiler under unix warns that 1.12345e-40 exceeds the range of
'double'.  It appears that the VAX compilers (gcc, cc, vcc) store doubles
in 32 bits, just like floats (legal C, but...).  Turbo C stores doubles
in 64 bits.

a_rubin@dsg4.dse.beckman.com (05/13/91)

In <127293@unix.cis.pitt.edu> yding@unix.cis.pitt.edu (Yijun Ding ) writes:

>Recently I have a program with small floatings. I find something works
>on my TC but not on mainframe. The following code, log10() print
>correctly on TC2.0. It is HUGE on unix, and 0 on VMS in University of
>Pittsburgh. That is a surprise.

>#include <math.h>
>main()
>{
>  double a=1.12345e-40;
>  printf("%lf %lf\n", a, log10(a));
>} 

>Any one can explain why?

I don't know about UNIX, but in VMS, 1.12345e-40 is calculated as a float,
rather than a double; hence it is 0.  (log10(0) is 0?  THAT is a bug.)
--
a_rubin@dsg4.dse.beckman.com  
My opinions are my own, and do not represent those of my employer.

wallyk@bicycle.WV.TEK.COM (Wally Kramer) (05/14/91)

yding@unix.cis.pitt.edu (Yijun Ding ) writes:
>Recently I have a program with small floatings. I find something works
>on my TC but not on mainframe. The following code, log10() print
>correctly on TC2.0. It is HUGE on unix, and 0 on VMS in University of
>Pittsburgh. That is a surprise.
>
>#include <math.h>
>main()
>{
>  double a=1.12345e-40;
>  printf("%lf %lf\n", a, log10(a));
>} 
>
>Any one can explain why?

This might not be the appropriate place for this discussion, however, I
myself frequently move software between VMS, Unix and MSDOS.

For a Unix system, I used UTek (a BSD derivative) running on a 68020 and
got the runtime result of

	0.000000 -39.949446

which looks correct to me (and is the same as I got under TC++ 1.0).

Naturally, for unix to link in a log10 function, you have to use
	cc small.c -lm

On VMS, I also got the same result, but it was a little more trouble.

	$ cc /g_float  small.c
	$ link small.obj, sys$input /option
	sys$share:vaxcrtlg /share
	^Z
	$ run small
	0.000000 -39.949446

The problem here is that the VAX floating point range used by 
default is D_floating:
                                           Mantissa   Approx.
               Bits            Range         bits     significant digits
  F_floating    32    .298e-38  to  1.7e+38   23       6-7
  D_floating    64    .298e-38  to  1.7e+38   55       15
  G_floating    64    .56e-308  to  .9e+308   53       15

VAXC, by default, uses F_float for "float" (unless the /precision=double
qualifier is used) and D_floats for "double".

For the magnitude of value you want to use, you should use the /g_float
qualifier in *all* your compilations.  Observe also that you link against
VAXCRTLG.EXE instead of VAXCRTL.EXE so that the library routines use
G_floats.
-----
Wally Kramer	contracted from Step Technology, Portland, Oregon 503 244 1239
wallyk@orca.wv.tek.com        +1 503 685 2658