|
Mathematical Signum function
|
|
03-12-2010, 02:44 AM
(This post was last modified: 03-18-2010 04:03 AM by drdebcol.)
Post: #1
|
|||
|
|||
|
Mathematical Signum function
This is an interesting and simple function which i haven't found in any of programming languages. It is easy to make so i decided to make it.
In mathematics, the sign function is an odd mathematical function that extracts the sign of a real number. Here is the mathematical definition : ![]() And you can find signum by using this formula : ![]() As you can see it is defined for every x from set of real numbers. And you can see that on this graphic : ![]() So it is mathematically simple, and in programming it is also easy to make. So here is the code in Pascal : Code: function sgn(x:real):shortint;Code: short sgn(float x)Basically it returns only 3 states (1,0,-1), so you can't use bool, but you can save memory by using shortint. I hope that you learned something from this, it can't be more simple ! And yeah, you can find more about it here on Wikipedia : http://en.wikipedia.org/wiki/Sign_function There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
03-12-2010, 09:39 PM
Post: #2
|
|||
|
|||
|
RE: Mathematical Signum function
hehe... interesting issue... I think i used something similar for one task of class all negative and positive numbers from one array in 2 other... If I find source, i will post it
Good point DrDebcol!
Read rules ![]()
|
|||
|
03-12-2010, 09:52 PM
Post: #3
|
|||
|
|||
RE: Mathematical Signum function
(03-12-2010 09:39 PM)l3g1sl4tor Wrote: hehe... interesting issue... I think i used something similar for one task of class all negative and positive numbers from one array in 2 other... If I find source, i will post itYeah this can be useful. I noticed that i forgot to mark 1 and -1 on graphic, but it is obvious ! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
03-13-2010, 07:13 AM
Post: #4
|
|||
|
|||
|
RE: Mathematical Signum function
Oh well... first i have looked is formula and program, so i didnt noticed also
Read rules ![]()
|
|||
|
« Next Oldest | Next Newest »
|



![[Image: 45159_sigumfunctiondefinition.jpg]](http://myph.us/pics/45159_sigumfunctiondefinition.jpg)
![[Image: 45160_sigumfunctiondefinition2.jpg]](http://myph.us/pics/45160_sigumfunctiondefinition2.jpg)
![[Image: 45161_signumfunctiongraphic.jpg]](http://myph.us/pics/45161_signumfunctiongraphic.jpg)




Good point DrDebcol!