Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

signum function

2 views
Skip to first unread message

Boris Breidenbach

unread,
Aug 31, 2000, 10:23:21 AM8/31/00
to
Hi!

I don't know Fortran very well, so excuse this stupid question!
Is there something like a signum function in Fortran 77?
What is it called? sgn doesn't work!

Bye,
Boris


--
----------------------------------------------------------

Boris Breidenbach
CERN Summer Student

Contact:
boris.br...@cern.ch
pa0...@stud.uni-wuppertal.de
----------------------------------------------------------

Boris Breidenbach

unread,
Aug 31, 2000, 10:22:46 AM8/31/00
to

me...@skyway.usask.ca

unread,
Aug 31, 2000, 5:15:23 AM8/31/00
to
In a previous article, Boris Breidenbach <Boris.Br...@cern.ch> wrote:
>Hi!
>
>I don't know Fortran very well, so excuse this stupid question!
>Is there something like a signum function in Fortran 77?
>What is it called? sgn doesn't work!
>
>Bye,
>Boris
sign(a1,a2) = (sign of a2) * a1

Herman D. Knoble

unread,
Aug 31, 2000, 12:00:21 PM8/31/00
to
FUNCTION ISIGNM(IX,MAXPOS)
! FUNCTION TO RETURN 0 IF IX=0, 1 IF 0<IX<MAXPOS+1,-1 OTHERWISE.
! MAXPOS is given as the maximum positive Integer.
INTEGER IX,MAXPOS
ISIGNM=1
IF(IX.LT.0.OR.IX.GT.MAXPOS)ISIGNM=-1
IF(IX.EQ.0) ISIGNM=0
RETURN
END
On Thu, 31 Aug 2000 16:22:46 +0200, Boris Breidenbach <Boris.Br...@cern.ch> wrote:

-|Hi!
-|
-|I don't know Fortran very well, so excuse this stupid question!
-|Is there something like a signum function in Fortran 77?
-|What is it called? sgn doesn't work!
-|
-|Bye,
-|Boris


Herman D. (Skip) Knoble, Research Associate
Mailto:h...@psu.edu
Web: http://www.personal.psu.edu/hdk
Center for Academic Computing
Penn State University
214C Computer Building
University Park, PA 16802-2101
Phone:+1 814 865-0818 Fax:+1 814 863-7049

ts

unread,
Sep 6, 2000, 6:21:19 PM9/6/00
to
Boris Breidenbach wrote:
>
> I don't know Fortran very well, so excuse this stupid question!
> Is there something like a signum function in Fortran 77?

sgn is not in the ftn intrinsic fcn set, however you can cut your own
with just a few lines of code, or use intrinsic "sign" fcn with a mod to
account for the difference (at 0) between the two. i.e.

sgn = sign(1,x)
if(x .eq. 0.) sgn = 0

--
T.Silva
-----------------------------------------------
Modeling * Simulation * Analysis
http://www.sdynamix.com
-----------------------------------------------

0 new messages