Chat on IRC |
How does math functions work?
Posted by Cortez [send private reply] at July 03, 2003, 06:16:32 AM
How does sin, log, sqrt work? Trigonometric functions and log might have a table, but what about sqrt?
Posted by CodeX [send private reply] at July 03, 2003, 08:45:59 AM
There's a method for finding the square root of a number. Some code for it was posted on planet source code about a month ago i suppose. Try searching for it there. I'm still not entirely sure how sin and log work. 5^x=25 is the same as log (base 5) 25=x, and somehow i suppose it could deduce x or something. I know there's a method for it out there somewhere, i mean, if it's in a programming language, there's got to be some logical way to do it.
Posted by Neumann [send private reply] at July 03, 2003, 09:16:30 AM
Check out GNU LibC sources, I suppose it's there. Microsoft even give away the source of their runtime library. It's on every good Visual Studio CD :)
Posted by regretfuldaydreamer [send private reply] at July 03, 2003, 01:43:28 PM
As all trigonometric functions can be deduced from sine, here is the sine series
sin x = x - ((x^3)/(3!)) + ((x^5)/(5!)) - ((x^7)/(7!)) + ((x^9)/(9!)) - etc... cos x = sqrt(1 - ((sin x)^2)) (I think theres a simpler way of getting cos from sin, I just can't remember it tan x = (sin x)/(cos x) as for square roots: log x^1/2 = 1/2 log x so a numbers square root is 10^(0.5logx)
Posted by Psion [send private reply] at July 04, 2003, 12:17:00 AM
rdd, those would be very inefficient ways to calculate these functions, so you can be pretty sure nobody uses them in language standard libraries, etc..
Posted by buzgub [send private reply] at July 04, 2003, 08:25:02 AM
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libm/src/ will show you how openBSD does it.
Posted by whizkide [send private reply] at July 05, 2003, 03:37:14 PM
rdd did u fail high school maths. easiest way to get cos from sin is to use the expression
sin^2x+cos^2x=1
Posted by Psion [send private reply] at July 05, 2003, 04:01:40 PM
That is what he used, whizkide. Did you fail junior high school algebra? ;)
Posted by whizkide [send private reply] at July 06, 2003, 11:10:09 AM
f**k sorry rdd. gotta go get them lenses.
Posted by regretfuldaydreamer [send private reply] at July 06, 2003, 12:34:38 PM
I remember in a really old programming book that standard libary functions were so slow to calculate sin etc. that at the start of a program requiring their use you should create an array and calculate all the values at initialisation.
Oh, and I should of indicated that my post shows one way of calculating these fuctions, not neccessarily how they are calculated by a computer.
Posted by Psion [send private reply] at July 06, 2003, 12:51:03 PM
To balance my counter-criticism of whizkide, I must point out that rdd has just typed "should of" and is now an honorary member of the Unwashed Masses Club.
Posted by regretfuldaydreamer [send private reply] at July 06, 2003, 12:54:36 PM
Unwashed Masses Club?
Posted by Kruptos [send private reply] at July 06, 2003, 09:25:51 PM
To find the square root of a number can't you just raise it to the 1/2 power? Why do you need to use logarithms? (I must be missing something fundamental here.)
Posted by taubz [send private reply] at July 07, 2003, 07:33:10 PM
And how exactly do you raise something to a non-integral power? :)
Posted by Kruptos [send private reply] at July 07, 2003, 10:50:40 PM
By letting a lower level function than the ones we're talking about figure it out :P ... Ok I getcha.
Posted by Psion [send private reply] at July 07, 2003, 11:11:00 PM
Pleasepleaseplease... stop adding to this thread!! ;-D
Posted by ItinitI [send private reply] at July 07, 2003, 11:39:02 PM
Why not lock it then?
Posted by Neumann [send private reply] at July 08, 2003, 07:55:20 AM
Why not force people to use the wiki by now? :D
Posted by Psion [send private reply] at July 08, 2003, 09:37:26 AM
We're all waiting for you to put your superior FrontPage into use, of course. :-)
Posted by Neumann [send private reply] at July 08, 2003, 10:05:26 AM
Hahah
Like if you need me for anything :P
Register as a new user | ||||||||||||||||||||||