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
0
votes
1 answer

Alglib with Cuda

I am pretty new with alglib and Cuda. I am trying to use Alglib for nonlinear list square fitting. Codes are working when I compile it in VC++ (.cpp) but when I am trying to compile same code but in a cuda file (.cu) it gives me this error: Error …
mohsen67
  • 3
  • 3
0
votes
1 answer

Build error for FABS, Xcode uses different header file (math.h vs tgmath.h)

I have a method which uses FABS return (fabs(x - y) <= EPSILON); It compiles and builds fine on four of my machines, but when I recently tried to configure another new machine i get a weird build error whereby it…
0
votes
1 answer

Math function compiler linking error

The following code compiles on other systems, but not on my Ubuntu 12.04 64bit guest in Virtualbox 4.3.10 on a Windows 7 64bit host. hello.c #include "header.h" int main(int argc, char *argv[]){ int i; for(i=0; i
0
votes
1 answer

Calculating sine of radian in C

Working on a simple school problem using C to calculate sine of 1 radian. #include #include #include int main(int argc, const char * argv[]) { double radian = (180 / M_PI); double y = sin(radian); …
azochz
  • 1,006
  • 4
  • 12
  • 20
0
votes
2 answers

Casting value from pow/powl to Long Long in C

In C, I am trying a few different things, but am not sure which is most efficient. I am trying to have a power function returns Originally I had long long rhs = num % (long long) pow(10, pos); but this gave errors as the power became high. I…
apache
  • 567
  • 1
  • 5
  • 9
0
votes
2 answers

How pow function works in this case?

#include #include int main() { int i = 11; printf("%d ^ 2 = %d\n",i,(int)pow(i,2)); getchar(); return 0; } In this case instead of getting 121,i am getting 120.What is the mistake i am making? (I really need to print pow(i,2) as…
0
votes
1 answer

C - Undefined reference - is there an alternative to compiling with -lm?

I have a problem much like the one here where the error is "Undefined reference to sqrt". I understand how using the -lm flag when compiling fixes the problem by linking it to the math library, however, are there any other possible ways to fix the…
mdw7326
  • 163
  • 1
  • 1
  • 9
0
votes
1 answer

C linker error with gcc and math.h

I am getting an error stating pythagorean.so: undefined symbol: cos. I am compiling with the math.h, stdlib.h, and stdio.h libraries and the -lm switch. Here a code snippet: static bool law_of_cosine_run(esh_command* cmd) { if…
Rich Episcopo
  • 499
  • 1
  • 5
  • 17
0
votes
2 answers

Is NAN returns false when accessing through pointer?

I am writing a function that returns a pointer to an array of numbers. To be able to iterate over the numbers using a pointer I set the last element to NAN to mark the end of the array. My Loop was something like for(int* it=ptr;!isnan(*it);++it) …
Moritz Petersen
  • 59
  • 1
  • 1
  • 8
0
votes
1 answer

Incompatible types when assigning to type 't_result' from type 'int', why?

I really don't understand why I get this error. architect.c: In function ‘main’: architect.c:91:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’ architect.c:93:20: error: incompatible types when assigning to type…
Anthony
  • 185
  • 1
  • 14
0
votes
1 answer

results of sine function different between microsoft and Java / Linux

I have a C++ code written for Windows (Visual Studio) which I need to port into Java. This is not very easy and currently I am stuck using the sine function in . The results given from Linux (tested to have a comparison) and Java are different as…
0
votes
2 answers

Passing variables to fmax

So I have the following code: #include int main (void) { float max = fmax (1.0,2.0); return 0; } Which compiles and runs fine, but if instead of passing 1.0 and 2.0 to the function I pass a, b with those values: #include int main…
Msegade
  • 476
  • 7
  • 17
0
votes
1 answer

fabs() not found in VS2012 debug mode (ANSI C)

I was compiling ANSI-C in VS2012 (with _CRT_SECURE_NO_WARNINGS set) and the program uses "math.h". And I encounter the following problems: sqrt() The automatic checker for VS2012 will tell me there is an error IntelliSense: more than one instance…
bzk
  • 3
  • 3
0
votes
3 answers

Problem with conflict between mysql and math.h

The problem is that the compiler says that there is a redefinition of a function between a library that belongs to MySQL and math.h from the std library. I have been over this for two days and I still can't figure it out. Has this ever happened to…
Pablo Herrero
  • 1,724
  • 5
  • 18
  • 23
0
votes
3 answers

Compiling in c++ with mysql, pthreads and gtk

Have someone ever done this before??? I am trying to use MinGW to compile a program using the MySQL libraries. I keep getting the message that the function 'rint' is redefined. Ok it's true that the function is in both files config-win.h, from MySQL…
Pablo Herrero
  • 1,724
  • 5
  • 18
  • 23