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
3
votes
6 answers

Floating point again

Yesterday I asked a floating point question, and I have another one. I am doing some computations where I use the results of the math.h (C language) sine, cosine and tangent functions. One of the developers muttered that you have to be careful of…
Xofo
  • 31
  • 1
3
votes
2 answers

fmod returns inconsistent value

Ran into an odd bug while trying to play around with some perlin noise functions. All of the sudden I got a off value in the middle of all of my calls. Traced it down to an inconsistent return value in fmod(). i=512; cout << i << "," <<…
jmurrayufo
  • 379
  • 2
  • 5
  • 14
2
votes
3 answers

Understanding C Header Syntax

I'm new to C. I was traveling through math.h, looking for its mathematical algorithms, but encountered only this kind of lines: _CRTIMP double __cdecl sin (double); _CRTIMP double __cdecl cos (double); ... Now, I couldn't find the algorithm…
Michael Sazonov
  • 1,531
  • 11
  • 21
2
votes
1 answer

fmin and fmax are much slower than simple conditional operator

I was working on some C++ code to process video frame, and found std::fmin and std::fmax is much slower than simply conditional operator. I've simplify my code as following (modify my code more C++ style as mentioned in comments): #include…
danry
  • 89
  • 4
2
votes
4 answers

Power function giving different answer than math.pow function in C

I was trying to write a program to calculate the value of x^n using a while loop: #include #include int main() { float x = 3, power = 1, copyx; int n = 22, copyn; copyx = x; copyn = n; while (n) { …
Abir Mondal
  • 23
  • 1
  • 5
2
votes
0 answers

GNU C library logarithm implementation

I have a question regarding the mathematical functions of the C standard library, to be precise the (natural) logarithmic function: On which mathematical approximation is the implementation based and how exactly is it implemented? An explanation for…
Mary
  • 63
  • 4
2
votes
0 answers

Does Intel MKL redefine functions from math.h in C?

I have an application written in C that uses math.h. I am wondering if I would benefit from linking with MKL at compile time, since I am not including mkl.h in my source code, and I intend not to use MKL directly in my source code. I only want to…
2
votes
3 answers

How to write a simple logarithm function without math.h?

This question I have didn't fully help me, although it gave me a few details. My current based code: #define e 2.7182818284590452353602874713527 double logarithm(long double dec) { // return log10f(dec); return result; } What I learned…
BMPL
  • 35
  • 16
2
votes
1 answer

Where did sincos go? (gcc c)

Couple days ago it was working fine, but trying to use again today, my code editor cannot find sincos anymore and GCC throws me a warning that it cannot find sincos when compiling. Here's the code: // file: main.c #include
aganm
  • 1,245
  • 1
  • 11
  • 30
2
votes
1 answer

Rust ffi + wasm (yew -> cargo web start) -> fatal error: 'math.h' file not found

I'm currently developing an application using C and Rust, where I don't have any problems when it's used in either of the following ways: C -> Rust -> C (swift) C -> Rust -> examples (console Rust) but it's getting complicated when I want to…
Stéphane
  • 143
  • 1
  • 10
2
votes
2 answers

Code::Blocks C++ compiling with MacOS Mojave : fatal error: sys/cdefs.h: No such file or directory

(This is my first question ever on StackOverflow) I have to use a Mac at work, and I'm coding in C++ with Code::Blocks (because I am used to this IDE). 2 days ago I upgraded from MacOS High Sierra to MacOS Mojave and I can fairly say that... it was…
FlatKos
  • 17
  • 1
  • 6
2
votes
1 answer

error: ‘::acos’ has not been declared using ::acos;

I encountered this error while trying to build a cpp project using CLion. Here is the error message: /usr/include/c++/5/cmath:102:11: error: ‘::acos’ has not been declared using ::acos; ^ /usr/include/c++/5/cmath:121:11: error:…
Zahra
  • 6,798
  • 9
  • 51
  • 76
2
votes
2 answers

Visual Studio 2017 Android NDK math.h

I'm trying to port some OpenGL ES code from windows to Android using the Android NDK. I'm using Visual Studio 2017 and C++. What I did so far, I created a cross platform gles project in VS and removed the ios data. I'm putting one code file after…
Eteru
  • 21
  • 3
2
votes
4 answers

Rounding (math.h) in C not working as it should

#include #include int main(){ printf("Rounded value of 6*0.95*0.25 = %.2f\n", round(6*0.95*0.25*100)/100); printf("Rounded value of 1.425 = %.2f\n", round(1.425*100)/100); } I have a suspicion that it is to do with the…
abaft
  • 152
  • 2
  • 12
2
votes
1 answer

How to include the math library in MS-VS 2005 compiler project settings?

I am trying to build a C program which was originally built on Linux with gcc -lm ... option, which uses the math library while linking the code. How can use the same in project settings of a Visual Studio 2005 compiler, on Win32 environment? EDIT:…
goldenmean
  • 18,376
  • 54
  • 154
  • 211