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

Finding the distance between 2 3D points

I'm running into a problem where my square of X is always becoming infinite leading to the resulting distance also being infinite, however I can't see anything wrong with my own maths: // Claculate distance xSqr = (x1 - x2) * (x1 - x2); ySqr = (y1…
TotalJargon
  • 147
  • 2
  • 2
  • 14
1
vote
2 answers

math function chosen by user

I'm writing some code which should use math function (from math.h) chosen by user. I have something like printf("If you want to use sin, press 's'\n" "If you want to use cosh, press 'c'\n"); do choice = getchar(); while (choice != 's' &&…
user1887999
1
vote
1 answer

Qt Creator and math.h does not work

I have started a Qt Project with Qt Creator and I want to use some mathematical functions. I have included math.h. But when I want to use a function, I got an error that the function is not declared in this scope. I also tried mathc, but then I got…
user1420447
  • 35
  • 1
  • 4
0
votes
0 answers

C - MCU code has 3 error prone regions on my graph output

I'm trying to output the tilt angle of an accelerometer, over serial with an MCU. The code works 99% smoothly for all angles, but I keep consistently getting errors in three regions and am not sure why. Here is a pic of the output data on a…
ezra_vdj
  • 133
  • 5
0
votes
2 answers

Scilab 2023 Xcos electrical demo does not work in Windows 10

I've just installed Scilab 2023 in Windows 10 with Visual Studio Buildtools successfully: --> haveacompiler() ans = T --> findmsvccompiler() ans = "Visual Studio Build Tools 2022" But when I try simulating Electrical Demo in Xcos, RLC,…
Salva
  • 1
  • 1
0
votes
1 answer

How does `math.h` refer to functions like `sin` or `cos`?

I see a plenty of similar questions, which are duplicates (like 12074147), but most of them are concerned with mathematical functions implementation. My question is more about C standard headers, like this one: #include What I'd be happy…
garej
  • 508
  • 1
  • 8
  • 24
0
votes
0 answers

Trying to compile a C program with GCC and math.h header

So, I'm trying to compile a simple C program in windows environment using GCC: #include #include int main(void) { printf("hi\n"); double x = sin(10); printf("%lf\n", x); return 0; } I use the following command to…
Lgcos
  • 91
  • 7
0
votes
1 answer

How do I properly link math.h library in makefiles?

I need to plot a function with gnuplot. This function requires the math.h library. Now I want to run it with a makefile. When I run the makefile I get this output/error: gcc -I./inc -o./build/result -lm ./src/main.c ./src/gnuplot.c /usr/bin/ld:…
FN-2187
  • 3
  • 2
0
votes
0 answers

problem with make file and math.h in gcc-arm-none-eabi

i'm working on arm cortex m4 with make file and gcc-arm-none-eabi on ubuntu. when i add math .h library to my project and try to use log10f , the linker exit with errors. its be good if help my for solve this problem and suggest source for more…
0
votes
0 answers

Why can't Compiler Explorer find ?

I am trying to compile a C module that includes math.h on Compiler Explorer, targeted at the ARM architecture. The compiler complains that it cannot find math.h regardless of the armclang version I am using. How can I get CE to find and include…
ysap
  • 7,723
  • 7
  • 59
  • 122
0
votes
2 answers

memset with math class macros

I am trying to use memset with INFINITY or NAN present in C header file My code is: double *dist; dist = (double *)malloc(7*sizeof(double)); memset(dist, INFINITY, 7*sizeof(dist[0])); However, on execution it gives me the following…
0
votes
1 answer

Status of tgmath.h in terms of portability across C, C++ compilers

I'm implementing a DSL with a compiler that translates it into C. Our code is self-contained: we provide users with just one main entry point (i.e., void step()), all inputs are given in global variables with simple types (bool, signed/unsigned…
Ivan Perez
  • 582
  • 2
  • 17
0
votes
0 answers

arm cortex log10 function sometimes returns 0

I'm using stm32f4xx mcu with lib when I convert the mW to dBm, used log10f() function but, the log10 function return value is not valid occasionally. here is my code: volatile float power = 0.0f; volatile float data = 0.0f; volatile int…
박동진
  • 1
  • 1
0
votes
0 answers

Unable to use exp() with a variable

This has been solved I am trying to use exp() from math.h in C, but it is failing to compile whenever I pass a variable as the argument. The following code works just fine #include #include int main() { printf("exp(x) =…
0
votes
1 answer

Math.h in Embedded systems

Is math.h in the standard library optimized for embedded systems especially ARM architecture (Cortex-M4)? If not what is the fastest alternative way to use math in a microcontroller?