comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: [Q]: ID analog to FORTRAN "sign" function
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: [Q]: ID analog to FORTRAN "sign" function [message #21929] Mon, 09 October 2000 00:00
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Alex Schuster <alex@pet.mpin-koeln.mpg.de> writes:
>> Results:
>> =========
>> The result type is the same as a.
>> The value of the result is
>> | a | if b >= zero
>> and -| a | if b < zero.
>
> No, but you can easily write it:
>
> function sign, a, b
> if ( b ge 0 ) then $
> return, abs( a ) $
> else $
> return, -abs( a )
> end

And, after the vector elf is done with it:

function sign, a, b
s = 2*(b GE 0) - 1 ;; +1 or -1
return, s*abs(a)
end

This function works with B as a scalar or a vector. If it's a vector
then it must have the same dimensions as A.

Craig

P.S. Recovering from pneumonia, Ugh.
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: [Q]: ID analog to FORTRAN "sign" function [message #21930 is a reply to message #21929] Mon, 09 October 2000 00:00 Go to previous message
Alex Schuster is currently offline  Alex Schuster
Messages: 124
Registered: February 1997
Senior Member
Rostyslav Pavlichenko wrote:

> Does the IDl have something close to Fortran SIGN (DSIGN... so on...)
> functions
>
> IN FORTRAN:
> Elemental Intrinsic Function (Generic):
> Returns the absolute value of the first argument times the sign of the
> second argument.
>
> Syntax:
> =======
> result = SIGN (a, b)
> a (Input) Must be of type integer or real.
>
> b Must have the same type and kind parameters as a.
>
> Results:
> =========
> The result type is the same as a.
> The value of the result is
> | a | if b >= zero
> and -| a | if b < zero.

No, but you can easily write it:

function sign, a, b
if ( b ge 0 ) then $
return, abs( a ) $
else $
return, -abs( a )
end

It works for both integer and float data types

Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: unformatted ascii data to arrays
Next Topic: SEGY format

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:16:19 PDT 2025

Total time taken to generate the page: 0.00696 seconds