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

C++ certainity of Integer Division with remainder

I have a question about performing of division with remainder of integers in C/C++. It is said that in operation of division between two integers, if the result can not be expressed as an integer, its part that is not integer are removed in…
user2561614
  • 51
  • 1
  • 6
2
votes
2 answers

C++ Windows alternative to lrint?

What is the correct alternative to the C99 lrint function in windows? #define lrint(x) (floor(x+(x>0) ? 0.5 : -0.5)) /* and if fesetround(0) behavior is required*/ #define lrint(x) ((int)(x)) is that correct?
Carlos Barbosa
  • 1,422
  • 2
  • 23
  • 42
2
votes
3 answers

C fabs returning integer

I have a strange problem with fabs function in C code. I have two double values and I want to find the absolute value of their difference using code like this: a = 87.967498; b = 218.025015; if (fabs(a-b)<2.0) ...code to execute The value of…
2
votes
1 answer

float fmodf(float_x, float_y) function, math.h, c++

hello I was hoping someone could help me with this. I am using the float fmodf(float_x, float_y) function from math.h. i am able to code with it properly but I was just wanted to know does anyone know the functions exact code is, so i can…
AlanF
  • 1,591
  • 3
  • 14
  • 20
2
votes
2 answers

Compiling and Linking KISSFFT

I have a newb problem with compiling and linking the kissfft library 'out of the box'. I've downloaded the kissfft library and extracted it to a test directory. Upon entering the directory and running 'make testall' I get the following errors,…
user1352331
  • 91
  • 1
  • 7
2
votes
2 answers

Math.h library functions in assembly x86?

I tried to convert C code that is written under Linux (fedora 9) to assembly x86 code, however, I have problem in a Math.h functions. The functions in this library such as ceil, floor, log, log10, pow are undefined in the assembly x86. Can you…
hamb
  • 159
  • 1
  • 2
  • 11
1
vote
3 answers

making your own pow()

I have a project where we are trying to get the code space down. We have one spot in one file that calls the pow() function from the math library which adds an additional +12k of code to the final hex for this one line of code. I have done some…
user1054210
  • 481
  • 1
  • 5
  • 11
1
vote
2 answers

Sinf - Does it exist in C++?

I was curious to know whether or not the sinf function existed in C++ through including math.h. When viewing my auto-completion in Qt Creator, it doesn't appear to pop up. It makes me wonder if, for some reason, it was taken out. A Google search…
zeboidlund
  • 9,731
  • 31
  • 118
  • 180
1
vote
4 answers

Squareroot returning not a number in C++

In the program below, I am trying to calculate the distance between two points. For this, I have made two Point objects. In the method that returns the distance, I have used the distance formula to calculate distance between two points in space.…
uyetch
  • 2,150
  • 3
  • 28
  • 33
1
vote
1 answer

How do I normalise the input value for acosf or asinf?

I need to obtain an inverse cosine and inverse sine from the result of a series of other calculations. If my input value is outside the range -1 to 1 then acosf or asinf return nan, which is expected given the definition of the function. How should…
jrturton
  • 118,105
  • 32
  • 252
  • 268
1
vote
1 answer

including cmath over math.h is causing incorrect results

Edited for test case and compiler inconsistency. Recently I made a change to use the more modern < cmath > instead of < math.h >. While this compiled just fine as expected with no warnings, this one-line change for one file caused my test cases to…
Brinck
  • 69
  • 4
1
vote
2 answers

MPLABX math.h error . (1510) non-reentrant function "___fleq" appears in multiple call graphs and has been duplicated by the compiler

Im working on a project about active power and reactive power measurement kit with using PIC16F877A MCU. In the code, I use pow, sqrt and cos functions which are included in math.h library. when I execute the code I get these errors. CLEAN…
El_Canario
  • 41
  • 3
1
vote
2 answers

Linking Math library to a C90 code using GCC

I would like to compile a simple C90 code utilizing math library: main.c: #include #include #include int main() { printf("M_PI: %f\n", M_PI); } I use GCC compiler and use option -ansi -pedantic to enforce C90…
Andree
  • 3,033
  • 6
  • 36
  • 56
1
vote
1 answer

Why the erf functions have no range error?

The erfcf(FLT_MAX) produces 0.0f and sets errno to ERANGE. The erff(FLT_MAX) produces 1.0f and does not set errno to ERANGE. In both cases returned results differ from the "true results" (i.e. obtained with infinite precision). Why ERANGE is set…
pmor
  • 5,392
  • 4
  • 17
  • 36
1
vote
2 answers

Error encountered while defining a function to calculate the Euclidean distance between two points using a struct

I created a function to calculate the Euclidean distance between two points in C (written in the Codeblocks IDE), however some errors occurred: error: expected ')' before 'p1'| error: expected expression before ',' token| The errors above…
Randy Chen
  • 107
  • 8