ghe@physics.orst.edu (Guangliang He) (05/09/91)
Can anyone tell me what kind result I should expect from the following little
C program?
-----
#include <stdio.h>
main()
{
int i;
for (i = 0; i < 10; i++)
printf("%e\n", drand48());
}
-----
The answer I got from a RS/6000 is following:
1.531272e-154
1.531272e-154
1.531272e-154
1.531272e-154
1.531272e-154
1.531272e-154
1.531272e-154
1.531272e-154
1.531272e-154
1.531272e-154
While the answer from a SUN is
3.964646e-01
8.404851e-01
3.533361e-01
4.465833e-01
3.186927e-01
8.864284e-01
1.558284e-02
5.840898e-01
1.593685e-01
3.837159e-01
What is the problem on RS/6000? Is it a BUG in drand48() or is it 'work
as designed'??? :-( :-(
---
Guangliang He | -----Go Blazers!-----
ghe@physics.orst.edu | -----Go Blazers!-----
andreess@mrlax1.mrl.uiuc.edu (Marc Andreessen) (05/09/91)
In article <1991May08.214654.26143@lynx.CS.ORST.EDU> ghe@physics.orst.edu writes: >#include <stdio.h> > >main() >{ > int i; > > for (i = 0; i < 10; i++) > printf("%e\n", drand48()); >} >What is the problem on RS/6000? Is it a BUG in drand48() or is it 'work >as designed'??? :-( :-( Neither. Try declaring drand48 as double before using it. Marc -- Marc Andreessen___________University of Illinois Materials Research Laboratory Internet: andreessen@uimrl7.mrl.uiuc.edu____________Bitnet: andreessen@uiucmrl
jackk@shasta.Stanford.EDU (jackk) (05/09/91)
In article <1991May08.214654.26143@lynx.CS.ORST.EDU> ghe@physics.orst.edu writes: >Can anyone tell me what kind result I should expect from the following little >C program? >----- >#include <stdio.h> > >main() >{ > int i; > > for (i = 0; i < 10; i++) > printf("%e\n", drand48()); >} >----- > >The answer I got from a RS/6000 is following: >1.531272e-154 >1.531272e-154 >1.531272e-154 > >While the answer from a SUN is >3.964646e-01 >8.404851e-01 > >What is the problem on RS/6000? Is it a BUG in drand48() or is it 'work >as designed'??? :-( :-( > Please read the manual pages for this function. The SUN manual says quite clearly: srand48(), seed48(), and lcong48() are initialization entry points, one of which should be invoked before either ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ drand48(), lrand48(), or mrand48() is called. ^^^^^^^^^^^^^^^^ Try following the directions and see if it works. Jack
andreess@mrlaxs.mrl.uiuc.edu (Marc Andreessen) (05/09/91)
In article <189@shasta.Stanford.EDU> jackk@shasta.Stanford.EDU (jackk) writes: >Please read the manual pages for this function. The SUN manual says >quite clearly: > >srand48(), seed48(), and lcong48() are initialization entry > points, one of which should be invoked before either > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > drand48(), lrand48(), or mrand48() is called. > ^^^^^^^^^^^^^^^^ Nope, not the case. Quoting from the AIX docs: (Although it is not recommended practice, constant default initializer values are supplied automatically if the drand48, lrand48 or mrand48 subroutines are called without first calling an initialization subroutine.) Marc -- Marc Andreessen___________University of Illinois Materials Research Laboratory Internet: andreessen@uimrl7.mrl.uiuc.edu____________Bitnet: andreessen@uiucmrl
ghe@physics.orst.edu (Guangliang He) (05/09/91)
In article <1991May08.214654.26143@lynx.CS.ORST.EDU>, ghe@physics.orst.edu (Guangliang He) writes: |> Can anyone tell me what kind result I should expect from the following little |> C program? |> ----- |> #include <stdio.h> |> |> main() |> { |> int i; |> |> for (i = 0; i < 10; i++) |> printf("%e\n", drand48()); |> } |> ----- |> |> |> What is the problem on RS/6000? Is it a BUG in drand48() or is it 'work |> as designed'??? :-( :-( |> |> --- |> Guangliang He | -----Go Blazers!----- |> ghe@physics.orst.edu | -----Go Blazers!----- |> -- As Marc (jackk@shasta.Stanford.EDU) pointed in a Email message, declearing double drand48() fix the problem on AIX. Sorry for the confusion, folks. But I'm still wondering why the program worked on SUN without declearing double drand48(), What is the difference between two compilers? --- Guangliang He | -----Go Blazers!----- ghe@physics.orst.edu | -----Go Blazers!-----
jackk@shasta.Stanford.EDU (jackk) (05/09/91)
>|> >|> What is the problem on RS/6000? Is it a BUG in drand48() or is it 'work >|> as designed'??? :-( :-( >|> >|> --- >|> Guangliang He | -----Go Blazers!----- > >As Marc (jackk@shasta.Stanford.EDU) pointed in a Email message,declearing ^^^^^^ not his address ---I was wrong about the initialization... he was right about the declaration >double drand48() fix the problem on AIX. Sorry for the confusion, folks. > >But I'm still wondering why the program worked on SUN without declearing >double drand48(), What is the difference between two compilers? > Actually, it fails on my SUN/4 without the declaration as well, so perhaps its a feature of a specific version of a Sun compiler.
madd@world.std.com (jim frost) (05/17/91)
>>But I'm still wondering why the program worked on SUN without declearing >>double drand48(), What is the difference between two compilers? >> >Actually, it fails on my SUN/4 without the declaration as well, >so perhaps its a feature of a specific version of a Sun compiler. Many RISC architectures do FP returns in FP registers and int returns in int registers. If you don't declare them you get the return from the GPR rather than the FPR, which is bogus. Many architectures have similar problems for func-returns-struct -- a number of them pass the address for the return as a hidden argument. If you don't properly declare your function, you goof up both incoming and outgoing. The '6000 uses both of these conventions as well as using registers as arguments. See info article on "Subroutine Linkage Convention". Note, however, that FP arguments are *always* shadowed in GPRs although the info document says otherwise. One would assume that's for compatibility with K&R-style varargs functions. Happy hacking, jim