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
4
votes
2 answers

C++ math functions can be used without including the directive "math.h" in VS 2013

I am very curious why I can use the math functions in C++ without including the "math.h". I can't find an answer with google search. Here is the simple code I am executing. Everything is compiling and running. #include using namespace…
Christian Rizov
  • 331
  • 2
  • 11
4
votes
4 answers

sqrt is only defined when argument is nonnegative

This compiles fine #include int main(void) { double i = sqrt(9.0); } If I change 9.0 to -9.0, then my compiler (GNU C) gives an error about an undefined reference to 'sqrt'. I was expecting the sqrt function to return NaN or an…
countunique
  • 4,068
  • 6
  • 26
  • 35
4
votes
2 answers

math.h linker error using sin() in C

I have two segments of code, both identical except for one line. One program fails to compile, and the other one is successful. I do link the math libraries when I execute cc to compile the code. I'm using the double sin(double) function. It's…
Timothy Legg
  • 41
  • 1
  • 3
4
votes
2 answers

Disable math.h crap when working with cmath

I had a problem previously because of functions being overloaded without std::. And the curse is still happening every now and then because I don't use using namespace std;. Removing using namespace std causes the program to get crap results Is…
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
4
votes
3 answers

C: Undefined reference to floor

I am using Eclipse on Ubuntu to write/compile/run C code. I am trying to build my project. Following is the output in the Eclipse console. 22:18:31 **** Build of configuration Debug for project Project1 **** make all Building file:…
Akshay7589
  • 61
  • 1
  • 1
  • 5
4
votes
7 answers

Visual C++ math.h bug

I was debugging my project and could not find a bug. Finally I located it. Look at the code. You think everything is OK, and result will be "OK! OK! OK!", don't you? Now compile it with VC (i've tried vs2005 and vs2008). #include #include…
f0b0s
  • 2,978
  • 26
  • 30
4
votes
3 answers

Storing numbers with higher precision in C

I am writing a program in which I need to store numbers with a very high precision(around 10^-10) and then further use them a parameter( create_bloomfilter ([yet to decide the type] falsePositivity, long expected_num_of_elem) ). The highest…
Aman Deep Gautam
  • 8,091
  • 21
  • 74
  • 130
3
votes
4 answers

Turbo C compiler issue, sqrt() function not working with variable arguments

I searched the question similar to my problem Similar problem. But my problem is when using Turbo C compiler v3.0. Should I have to do some additional work for math.h file? please help. int main (void){ double result, a; clrscr(); …
AbdulAziz
  • 5,868
  • 14
  • 56
  • 77
3
votes
1 answer

tan ( pi/2 ) in objective-c (math.h) not undefined

I wrote this test code: NSLog(@"%g", tan(M_PI / 2.0)); and the output of the console is: 1.63312e+16 The issues is about approximation, right? Did I make some mistakes or the tan function of math.h really doesn't handle this case itself (returning…
Massimo
  • 112
  • 2
  • 9
3
votes
1 answer

difference dev-cpp and Microsoft Visual C++ math.h

a few days ago, I worked on project in VC++. I found out, that math.h in VC++ differs much from dev-cpp math.h. Particulary its round function, that is not present in Visual C++ math.h, but is contained in dev-cpp math.h. Now I would like to ask,…
3
votes
2 answers

If the next representable value after -0.0 is +0.0, then why nextafter(-0.0, INFINITY) does not return +0.0?

If the next representable value after -0.0 is +0.0, then why nextafter(-0.0, INFINITY) does not return +0.0?
pmor
  • 5,392
  • 4
  • 17
  • 36
3
votes
1 answer

GCC error undefined reference to `sqrt' on changing command option order

Why I am getting the following error /tmp/ccuWdVB3.o: In function `test': MyCode.c:(.text+0x1c): undefined reference to `sqrt' collect2: error: ld returned 1 exit status MyCode.c #include #include int test(int input1) { int x…
Aayush Jain
  • 183
  • 1
  • 11
3
votes
0 answers

FLT_HAS_SUBNORM is 0: does execution of fpclassify() with manually constructed subnormal lead to UB or lead to WDB returning FP_SUBNORMAL?

In case of FLT_HAS_SUBNORM == 0 (or any XXX_HAS_SUBNORM == 0 in general) does execution of fpclassify macro with manually constructed subnormal (constructed using type punning via union, using memcpy, reading from file, etc.) lead to undefined…
pmor
  • 5,392
  • 4
  • 17
  • 36
3
votes
1 answer

FLT_MAX for half floats

I am using CUDA with half floats, or __half as they are called in CUDA. What is the half-float equivalent of FLT_MAX? The cuda_fp16.h header does not seem to have a macro that resembles this. $ grep MAX…
Bram
  • 7,440
  • 3
  • 52
  • 94
3
votes
0 answers

math library for half-precision numbers

I want to use half-precision arithmetic on Cortex-A76. I installed clang compiler to use _Float16 data type (which is for 16-bit arithmetic purpose). I was wondering is there any library for half-precision mathematic functions? (like for…
Sooora
  • 171
  • 9