M
M
mlyamasov2020-07-05 11:59:27
Haskell
mlyamasov, 2020-07-05 11:59:27

Why is there a signum function in the Num class?

Can you give examples of using this function?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
wiz, 2020-09-05
@mlyamasov

mlyamasov , is a relative of abs from the world of complex numbers:

That is, abs zis a number with the magnitude of z, but oriented in the positive real direction, whereas signum zhas the phase of z, but unit magnitude.

https://www.haskell.org/onlinereport/complex.html
The Num class is indeed considered by many to be an overcomplicated monster, but now it is with us until the next report.

M
Maxim Moseychuk, 2020-07-05
@fshp

And what about Haskell? This is a general mathematical function.
https://ru.m.wikipedia.org/wiki/Sgn

K
kornietsbk, 2020-07-23
@kornietsbk

The signum function determines the sign of the number passed to it as an argument.

Prelude> signum 4
1
Prelude> signum (-4)
-1

Returns 1 - if the number is positive; -1 - if the number is negative

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question