Previous Page Next Page Contents

sign -- the sign of a real or complex number

Introduction

sign(z) returns the sign of the number z.

Call(s)

sign(z)

Parameters

z - an arithmetical expression

Returns

an arithmetical expression.

Overloadable:

z

Side Effects

sign respects properties of identifiers. For real expressions, the result may depend on the value of the environment variable DIGITS.

Related Functions

abs, conjugate, Im, Re

Details

Example 1

We compute the sign of various real numbers and expressions:

>> sign(-8/3), sign(3.2), sign(exp(3) - sqrt(2)*PI), sign(0)
                                -1, 1, 1, 0

The sign of a complex number z is the complex number z/abs(z):

>> sign(0.5 + 1.1*I), sign(2 + 3*I), sign(exp(sin(2 + 3*I)))
                                                       1/2
      0.4138029443 + 0.9103664775 I, (2/13 + 3/13 I) 13   ,
      
         exp(I cos(2) sinh(3))

Example 2

sign yields a symbolic, yet simplified, function call if identifiers are involved:

>> sign(x), sign(2*x*y), sign(2*x + y),  sign(PI*exp(2 + y))
            sign(x), sign(x y), sign(2 x + y), sign(exp(y + 2))

In special cases, the expand function may provide further simplifications:

>> expand(sign(2*x*y)), expand(sign(PI*exp(2 + y)))
                       sign(x) sign(y), sign(exp(y))

Example 3

sign respects properties of identifiers:

>> sign(x + PI)
                               sign(x + PI)
>> assume(x > -3): sign(x + PI)
                                     1
>> unassume(x):

Example 4

The following rational number approximates PI to about 20 digits:

>> p := 157079632679489661923/50000000000000000000:

With the standard precision DIGITS = 10, the float test inside sign does not give a decisive answer, whether p is larger or smaller than PI:

>> float(PI - p)
                                    0.0

This result is subject to numerical roundoff and does not allow a conclusion on the sign of the number PI - p. The float test inside sign checks the reliablity of floating point approximations. In this case, no simplified result is returned:

>> sign(PI - p)
           sign(PI - 157079632679489661923/50000000000000000000)

With increased DIGITS, a reliable decision can be taken:

>> DIGITS := 20: sign(PI - p)
                                     1
>> delete p, DIGITS:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000