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
1
vote
1 answer

Math.h not working properly?

I'm having a very strange problem which has been driving me crazy for a while. Part of my code requires c++ to calculate some simple arithmetic using math.h, but it is spitting out completely incorrect values! Here is this section of the…
khfrekek
  • 211
  • 1
  • 5
  • 12
1
vote
2 answers

double to int conversion not working using math.h functions in c

dataBuf[1] = acos(0.130f); This is the code I'm running but when I print out the result, it comes out as 1 instead of 82. dataBuf is an int16_t array. All the other math.h functions work fine with the conversion but the trig ones don't work.
jack sexton
  • 1,227
  • 1
  • 9
  • 28
1
vote
1 answer

C - simple math argument not working?

I am just trying to calculate an amount for 10 years, using a relatively simple formula. I can input all of my variables, but I suspect I'm doing something wrong with the amount. #include #include int main(){ double amount;…
user3718365
  • 515
  • 3
  • 6
  • 13
1
vote
1 answer

Carve 1.4 CSG - C2375: 'cbrt' : redefinition; different linkage

I am trying to compile Carve 1.4 c++ library. but keep getting C2375: 'cbrt' : redefinition; different linkage errors. When i click on an error it takes me to this line in math.h: _CRTIMP double __cdecl cbrt(_In_ double _X); the only other cbrt…
1
vote
1 answer

Taking away the comments in front of "#include " destroys my code

The program will ask the user to enter the real and imaginary parts of two complex numbers. The program should output the sum, difference, product, quotient, and absolute value of the complex numbers formatted to two decimal places. Everything has…
Sean
  • 47
  • 5
1
vote
1 answer

ERROR in c program: ld returned 1 exit status

This is a simple program to draw the sine curve using c program. unfortunately,I got this error : undefined reference to 'sin' #include #include #include main() { int i; int offset; char sinstr[80]; …
user3717117
1
vote
0 answers

C math. h functions are "undefined references" in Ubuntu

I'm a complete newbie in C for Linux. I have this function (tested on Visual Studio, it works and it's not using any C++ or Windows-only functions) that returns the amount of digits inside an integer number (note the use of log10() from math.h), but…
soulblazer
  • 1,178
  • 7
  • 20
  • 30
1
vote
2 answers

math functions in thread returning wrong values, with android ndk

I am having an issue while trying to port a code to Android NDK, which is doing fine on iOS. The code renders 3D models and uses openGL ES 1.1 for that, so it performs many calculations using the standard c math library (including math.h). Here is a…
Jserra
  • 159
  • 1
  • 9
1
vote
1 answer

What does __tg_promote do in tgmath.h

I'm looking at tgmath.h and trying to understand exactly how it selects the correct function based on the size of the input value. The special sauce seems to be this __tg_promote macro but the deeper I dig the deeper this puzzle gets. Does anyone…
Awesome-o
  • 2,002
  • 1
  • 26
  • 38
1
vote
3 answers

Can C++ Headers be called vector.h or matrix.h?

I have including problems in a C++ Project. I included math.h, but there are strange problems with my vector.h and my matrix.h header files. Am I allowed to call these files vector.h and matrix.h?
user3075425
  • 332
  • 1
  • 6
  • 23
1
vote
1 answer

math.h functions in lldb not working

Is it possible to call functions from math.h while using the lldb debugger? I am trying to debug some math-related iOS code and am getting incorrect results from the Xcode5 debugger: (lldb) p (double)pow(2., 2.) (double) $0 = NaN Another post…
tboyce12
  • 1,449
  • 14
  • 28
1
vote
1 answer

The Sieve of Eratosthenes in C using arrays

I'ma beginner in C and I have to convert The Sieve of Eratosthenes algorithm into C code. This is the algorithm given: *START Initialize the array is_prime so that all the values of the elements will be TRUE. set the value of is_prime[1] to be…
C_Intermediate_Learner
  • 1,800
  • 3
  • 18
  • 22
1
vote
1 answer

Using C math.h to calculate the sin of a number

I'm an absolute beginner to C and I've read a few books but never really played with it. I'm starting to try to apply what I've read with a very simple program that returns the sin of a number. The hardest thing I've encountered with C is knowing…
nullByteMe
  • 6,141
  • 13
  • 62
  • 99
1
vote
2 answers

math.h pow() function not working correctly?

I was working on a personal project in which I needed to determine all prime powers between 0 and 999. Because I am not particularly good at math, I tired the following ham-fisted bruteforce approach. bool constexpr is_prime(int imp) { return…
Byzantian
  • 3,208
  • 4
  • 27
  • 31
1
vote
1 answer

How do I (dynamically) link against math.h functions on Windows?

I'm working on a C++ app which uses the LLVM JIT backend to compile code on the fly. In this JIT-compiled code, I want to be able to call all of the math.h functions, but currently it only works for some of them, i.e. fabs is present but fabsf is…
Ben
  • 843
  • 8
  • 21