🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #2459

Re: Fortran vs. C for numerical work

#2459
From: Joe English Muffin
Date: Sun, 09 Dec 1990 18:11
63 lines
2470 bytes
Bruce.Hoult@bbs.actrix.gen.nz writes:

>In article <77124@iuvax.cs.indiana.edu> templon@copper.ucs.indiana.edu (jeffrey templon) writes:


>>  IF ( a .lt. 0.0) THEN
>>     b = sqrt(-1.0*a)
>>  ELSE
>>     b = sqrt(a)
>>  ENDIF

>That's a turn-around!  I forget the exact syntax (haven't used FORTRAN for a
>decade), but can't you do this in FORTRAN?

>   IF(a) 1111,1112,1113
>1111   b = sqrt(-1.0*a)
>   GO TO 1114
>1112   b = 0
>   GO TO 1114
>1113   b = sqrt(a)
>1114   CONTINUE

Sure, you can also do this in C:

    if (a < 0.0) goto label1;
    else if (a > 0.0) goto label2;
    else if (a == 0.0) goto label3;
    else exit(1);
label1:     b = sqrt(1.0 * -a); goto label4;
label2:     b = sqrt(1.0 * a) ; goto label4;
label3:     b = sqrt(1.0 * 0.0); goto label4;
label4:     ;

What's your point?  Personally, I'd be much more likely
to use 

    b = sqrt(fabs(a));      or         B = SQRT(ABS(A))

in either case.  Just a matter of style, I guess.


>>  another reason (vms-specific) is that vms C uses the CALLS instruction
>>to jump to a subroutine, as compared to fortran using CALLG.  

>In C or Pascal you could allocate a structure as a global (static) variable,
                                                    ^^^^^^^^^^^^^^
To allow recursion, the compiler would have to allocate this
as 'auto,' in the caller's stack frame.

>assign your parameters into it and just pass a pointer to the structure to
>the called routine.  The compiler might even be smart enough to use CALLG,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Probably not.  Since there's always the possibility that the
function will be called from somewhere without a prototype in
scope, parameter block argument passing wouldn't be a feasible
scheme.



--Joe English

  jeenglis@alcor.usc.edu
Technical Details
Message-ID: <13552@chaph.usc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!usc!chaph.usc.edu!alcor.usc.edu!jeenglis
References: <18016@hydra.gatech.EDU> <16671@csli.Stanford.EDU> <77124@iuvax.cs.indiana.edu> <1990Dec9.040635.12696@actrix.gen.nz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!usc!chaph.usc.edu!alcor.usc.edu!jeenglis
From: jeenglis@alcor.usc.edu (Joe English Muffin)
Newsgroups: comp.lang.misc
Subject: Re: Fortran vs. C for numerical work
Message-ID: <13552@chaph.usc.edu>
Date: 9 Dec 90 18:11:31 GMT
References: <18016@hydra.gatech.EDU> <16671@csli.Stanford.EDU> <77124@iuvax.cs.indiana.edu> <1990Dec9.040635.12696@actrix.gen.nz>
Sender: news@chaph.usc.edu
Organization: USC Co-Ed Naked Depressed Person's Softball League
Lines: 63
Nntp-Posting-Host: alcor.usc.edu