Questions tagged [math.h]

For questions relating to functions declared by the math.h header file of C programming language.

Most of the mathematical functions are placed in math.h header (cmath header in C++).
math.h header file has following functions:

int abs (int x);                    
long labs (long x);

double fabs (double x);
double sin (double x);
double cos (double x);
double tan (double x);
double asin (double x);
double acos (double x);
double atan (double x);
double sinh (double x);
double cosh (double x);
double tanh (double x);

double exp (double x);              ex
double log (double x);              ln x
double log10 (double x);            log x

double pow (double x,double y);     xy
double sqrt(double x);              square root of x
double fmod(double x, double y);    x mod y

double ceil (double x);
double floor(double x);
310 questions
6
votes
6 answers

Is there a Java equivalent of frexp?

Is there a Java equivalent of the C / C++ function called frexp? If you aren't familiar, frexp is defined by Wikipedia to "break floating-point number down into mantissa and exponent." I am looking for an implementation with both speed and accuracy…
Bob Cross
  • 22,116
  • 12
  • 58
  • 95
5
votes
1 answer

A linking error related to 'gcc' and '-lm'

Well, I think my problem is a little bit interesting and I want to understand what's happening on my Ubuntu box. I compiled and linked the following useless piece of code with gcc -lm -o useless useless.c: /* File useless.c */ #include…
LucasBr
  • 461
  • 1
  • 7
  • 19
5
votes
2 answers

Undefined reference to exp on Ubuntu (including math.h and linking with -lm)

I'm having some trouble trying to compile a program that uses exp function on Ubuntu. I get this error from gcc: selied@Apolo:~/Dropbox/practicas UAM/Neuro/practica3$ make gcc -lm -o retropropagacion retropropagacion.o retropropagacion.o: In…
Selied
  • 53
  • 1
  • 1
  • 3
5
votes
4 answers

erf(x) and math.h

According to this site the error function erf(x) comes from math.h. But actually looking in math.h, it isn't there, and gcc cannot compile the following test program while g++ can: #include #include int main(int argc, char*…
user76293
  • 559
  • 2
  • 5
  • 14
5
votes
2 answers

float_t and double_t format specifiers

There are new format specifiers for intN_t types, for example %"PRIiN" and %"SCNiN", for printf and scanf families of functions. What are, if any, the new format specifiers for float_t and double_t? (defined in math.h) Can I -safely- use %f and %lf?…
5
votes
2 answers

Why fabs() doesn't require the -lm option when compiling with GCC

I have written a simple program fabs.c to display the absolute value of a floating point number. #include #include int main(void) { float f; printf("Enter a floating-point number: "); scanf("%f", &f); …
LinuxBabe
  • 387
  • 2
  • 6
5
votes
1 answer

Looking for a pure c-version of math.h functions (no co-processor support)

I have to work with some (semi-)automatical verification software (CBMC (link)) which is statically working on C sources. Floating point is supported, but there are no definitions for all the mathematical functions. The attempt is to check, if it's…
sascha
  • 32,238
  • 6
  • 68
  • 110
5
votes
1 answer

Why am I getting this error when trying to use log from math.h in C?

I need to use logs in a program for an assignment. I ran this test program on my machine to see how the log function works (and if it would), and I get the following error during build. Code /* log example */ #include /* printf…
user2608931
5
votes
5 answers

c equavilent to matlab's sind and cosd function

So I am working with some matlab code converting to c code by hand. I am just wondering if there is a c equivalent to the sind and cosd functions I'm seeing in the matlab code. I guess this returns the answer in degrees rather than the c sin and…
Matthew The Terrible
  • 1,589
  • 5
  • 31
  • 53
5
votes
0 answers

How are sin(x) or cos(x) in math.h implemented?

Possible Duplicate: How does C compute sin() and other math functions? I'm curious how sin and cos the are implemented on a low level. I just had a look inside the math.h and couldn't find the declaration for sin and cos. But since this was a…
devsnd
  • 7,382
  • 3
  • 42
  • 50
4
votes
2 answers

pow() from math.h library - How to Apply using functions

So I'm writing a bit of code that needs to raise a function's return value to a certain power. I recently discovered that using the '^' operator for exponentiation is useless because in C++ it is actually an XOR operator or something like that. Now…
Ram Sidharth
  • 183
  • 4
  • 4
  • 11
4
votes
2 answers

How to use math functions with gdb

I am a student and I faced a problem: When I use pow or asin in my Linux programs and try to debug it with GDB I get the error: undefined reference to 'pow'. I know that to fix this in the GCC compiler, I need to add the -lm key. Is there some key…
4
votes
3 answers

Error function, erf(x), not found in math.h for visual studio 2005

It seems that cmath for visual studio 2005 does not have erf(x). I am using NIST Statistical Test Suite for Random and Pseudorandom Number Generators. In cephes.c's method, double cephes_normal(double x), it uses a C99 math function erf(x) which I…
Maelstrom Yamato
  • 167
  • 1
  • 2
  • 7
4
votes
1 answer

Why is acos() resulting in "nan(ind)" when using the result of a dot product?

I'm very confused with the issue. The code I am running is: double dotProduct = dot(A, B); std::cout << dotProduct << std::endl; theta = acos(dotProduct); std::cout << theta << std::endl; The output of which is -1 ANGLE: -nan(ind) However, the…
Brendan M
  • 51
  • 1
  • 4
4
votes
1 answer

Vivado SDK doesn't recognize the functions inside #include "math.h"

I wrote a simple project in Vivado SDK in order to test my HW-platform developed in Vivado. My problem is that the SDK doesn't recognise the sin() function. I've included the "math.h" library without any error, the program recognise the library…
Arturete
  • 133
  • 2
  • 12
1 2
3
20 21