This question already has answers here:
How does C compute sin() and other math functions?
(22 answers)
Closed 9 years ago.
Anybody can explain or show how is the function "sin" (or "sinf", "sinl") realized in C.
Intuition suggests that it should be somewhere in the math.h but I did not see anything there
There's a couple ways I can think of right off the bat:
Lookup tables
Approximation via Taylor series (which can be easily made accurate to a number of significant digits).
Related
This question already has answers here:
What is the behavior of integer division?
(6 answers)
Closed 5 years ago.
So I am trying to learn how to divide fractions. I am confused why dividing variables gives the correct result, and dividing the numbers themselves gives an incorrect result. I have tried to searching on here and couldn't find anything relevant. Here is an image to show why I am talking about.
The expression 1 / 3 is an integer expression. You divide two int values. That leads to truncation.
Try e.g. 1.0 / 3.0 instead.
This question already has answers here:
getting free unit number in fortran
(2 answers)
Closed 7 years ago.
I can write a FORTRAN function to find an available file unit, but I was certain there was already an intrinsic. But if there is, I can't find anything about it. Is there such a thing or am I dreaming?
UPDATE: Apologies for the duplicate. Did a search, but it didn't show up.
I guess, you are looking for newunit (available with F2008, shown at the bottom of that link in the Fortran Wiki).
Ups, has already been answered.
maybe you were thinking of inquire?
This question already has answers here:
How is the square root function implemented? [closed]
(15 answers)
Closed 8 years ago.
How does sqrt function really work ? Does it go by any logical theorem to get the result.
Is there any way i can access the code of libarary function such as sqrt?
You can download the source code from the libc, which is open source: http://www.gnu.org/software/libc/download.html
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Magic numbers of the Linux reboot() system call
I was asked this question in an interview
When using the Linux-specific reboot()
system call to reboot the system, the
second argument, magic2, must be
specified as one of a set of magic
numbers (e.g., LINUX_REBOOT_MAGIC2).
What is the significance of these
numbers?
What is the correct answer to the above question?
The significance of the allowed set of magic2 numbers is that, when expressed in hexadecimal, they represent dates-of-birth (specifically, of Linus Torvalds and his three children).
This really lowers the bar on silly interview questions!
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Converting a Uniform Distribution to a Normal Distribution
Hello.
I'd like to know of any algorithm implemented in C which can take a random value between 0 and 1, the mean and standard deviation and then return a normally distributed result.
I have too little brainpower to figure this out for myself right now.
I can't find anything useful on the internet.
Thank you.
Box-Muller is the transform you need.
There's already been the suggestion for Box Muller, but a computationally simpler approach is simply to take advantage of the central-limit theorem; add enough independent random variables together, and the result will approximate a normal distribution.