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

Does cmath borrow it's implementation from math.h

I want to switch from math.h to cmath for an embedded application. I am a bit skeptical about switching the from math.h to cmath lib, as this embedded system is quiet sensitive to change in precision from the computations. So I would like to know if…
Deepak Kiran
  • 195
  • 3
  • 15
0
votes
0 answers

How to set default Project Properties in NetBeans?

I create projects using C99 in NetBeans. But when I try to include the library math.h, sqrt() and cbrt() won't work. I am on Ubuntu and using Apache NetBeans IDE 11.2. It is updated to NetBeans 8.2 Patch 2. The steps I do are : File > New Project >…
0
votes
1 answer

Is there any way generalise program specific seting in vs code?

I was working with pow() function in c using vscode. And I want to use a variable in exponent parameter of power function i.e. pow (2, i). But i was getting error so, I used gcc programName.c -lm during compilation in terminal. Is there any way by…
0
votes
0 answers

OpenMP and math.h

I've been experimenting with openmp and some math functions in C. If I try to declare and initialize some variables outside a parallel construct, then use them within a math function inside the parallel, when I compile using gcc -fopenmp practice.c…
0
votes
0 answers

error LNK2019: unresolved external symbol cos referenced in function

I have been experiencing this issue for a while and I have not figured it out. I am not a programmer, I am an engineer that knows a little about coding so please be gentle. I am writing custom functions for MathCAD Prime and have used the examples…
amorenojr
  • 21
  • 3
0
votes
2 answers

Why doesn't math.h define the reciprocal trig functions?

I find little things like this throughout the C programming language; something that is very easy to provide, has very little chance of breaking old code, and has an obvious way to standardize it. Is minimalism the reason?
Jeff Linahan
  • 3,775
  • 5
  • 37
  • 56
0
votes
1 answer

Problem with Taylor Series implementation of logarithm

I tried to make a function output of which approximates the value of logarithm of x (x is a floating number) using the Taylor expansion. Taylor series of natural logarithm: ln(x) = {n=0 (sigma) inf} (-1)^n*(x-1)^(n+1)/(n+1) (used the sigma…
Hakan Demir
  • 307
  • 2
  • 4
  • 12
0
votes
1 answer

I have a problem compiling in C using third party libraries with "Scons"

Im creating a program in C and I am going to need some thermodynamics properties for water and steam. I have searched online and i found this library: http://freesteam.sourceforge.net On their website they advise to compile using something called…
0
votes
1 answer

why I am getting "Undefined symbol: .sqrtf" even after Including math.h and linking to math library using -lm

when I am tring to compile #include #include int main() { double m=1.66666; double k=sqrtf(m); return 0; } using following command /user/unicore/rs6000aix/compiler/gcc4.8.5/aix6.1/bin/gcc -o test.out test.cpp -lm it…
BitMask
  • 314
  • 2
  • 9
0
votes
1 answer

C program strange output and wrong output

Good evening. I was trying to to have the following program give me the average and round the average. So far I have the following. When using 's round function it returns a zero. Yes I have tried compiling with -std=99, -lm and…
0
votes
1 answer

C/C++ log10 function from math.h yields incorrect value

The following minimal example shows the issue: #include #include int main() { double a = log10(1/200); double b = log10(0.005); std::cout << "The value of a is " << a << " and b is " << b << std::endl; } I compile the…
Leigh K
  • 561
  • 6
  • 20
0
votes
1 answer

Problem calculating the perimeter of a shape by using structures in c++

The problem consists in that I have to use structures to calculate the perimeter of the shape. The data that is given to me are: the number of sides of the shape, the number of vertices that has the shape and the coordenates X and Y of each…
0
votes
0 answers

How to get microsoft c compiler to pre compute standard math functions for constants

GCC beautifully pre-computes the results of standard math functions at compile time when the input is a constant. Anyone know how to do the same with Microsoft C? I've tried everything and so far no joy. Code example: #include #include…
Johned
  • 143
  • 1
  • 9
0
votes
1 answer

Function log from math.h returns wrong

I was getting wrong values from log(), so I wrote this program just for testing: #include #include void main() { printf ("%1f", log(10)); } This should print "1", but I get "2.302585" Why is this and how can I fix it?
Luisini
  • 3
  • 1
0
votes
1 answer

_USE_MATH_DEFINES in C++ (VS2010)

I have got the following problem: I want to use M_PI defined in math.h. In order to do that, one should define _USE_MATH_DEFINES before including the header. The following solution works correctly: #define _USE_MATH_DEFINES and then #include <…
Jamie
  • 1,092
  • 3
  • 22
  • 44