[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: common-lisp at SU-AI
- Subject: SIGNUM function
- From: Guy.Steele at CMU-10A
- Date: Fri, 02 Jul 1982 17:03:00 -0000
Date: Wednesday, 30 June 1982, 17:47-EDT
From: Alan Bawden <Alan at SCRC-TENEX>
Subject: SIGNUM function in Common Lisp
Someone just asked for a SIGN function in LispMachine Lisp. It seems
like an obvious enough omission in the language, so I started to
implement it for him. I noticed that Common Lisp specifies that this
function should be called "SIGNUM". Is there a good reason for this?
Why not call it "SIGN" since that is what people are used to calling it
(in the non-complex case at least)?
I called it "SIGNUM" because that is what most mathematicians call it.
See any good mathematical dictionary. (Note, too, that the name of the
ACM special interest group on numerical mathematics is SIGNUM, a fine
inside joke.) However, people in other areas (such as applied mathematics
and engineering) do call it "SIGN". The standard abbreviation is SGN(X),
with SG(X) apparently a less preferred alternative.
As for programming-language tradition, here are some results:
* PASCAL, ADA, SAIL, and MAD (?) have no sign-related function.
* PL/I, BLISS, ALGOL 60, and ALGOL 68 call it "SIGN".
* SIMSCRIPT II calls it "SIGN.F".
* BASIC calls it SGN.
* APL calls it "signum" in documentation, but in code the multiplication
sign is used as a unary operator to denote it. (Interestingly, such
an operator was not defined in Iverson's original book, "A Programming
Language", but he does note that the "sign function" can be defined
as (x>0)-(x<0). Recall that < and > are 0/1-valued. I haven't tracked
down exactly when it got introduced as a primitive, and how it came
to be called "signum" in the APL community.)
* FORTRAN has a function called SIGN, but it doesn't mean the sign
function -- it means "transfer of sign". SIGN(A,B) = A*sgn(B),
but undefined if B=0.
I chose "SIGNUM" for Common LISP for compatibility with APL and mathematical
terminology, and also to prevent confusion with FORTRAN, whose SIGN function
takes two arguments. I don't feel strongly about the name. I observe,
however, that if the extension to complex numbers is retained, then
compatibility with APL, the only other language to make this useful
extension, may be in order. (The signum function on complex numbers
is elsewhere also called the "unit" or "unit-vector" function for
obvious reasons. It is called "unit" in Chris van Wyk's IDEAL language