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

Trouble using trig functions c++

I'm having trouble using the arcsine() function. When I use this code: #include #include using namespace std; int main() { cout << asin(12 / 13); } I get 0 as a result, whereas the calculator gives 30* which is 1/6…
0
votes
0 answers

What is the reason here that pow function not working correctly?

I am trying to write a program that gives output if the input is an integer (say 1234) 1234 234 34 4 I wrote the following code in C using codeblocks IDE : #include #include int main() { int a,l=0,b; print("Enter a number :…
Infinity_hunter
  • 157
  • 1
  • 7
0
votes
3 answers

sin() output of a double coming out as 0.00000. (C language)

#include #include #include int main(void) { int i; double interval; for(i=0;i<30;i++) { interval = i/10.0; printf("sin(%lf) = %lf \t", interval, abs(sin(interval))); …
0
votes
0 answers

How do I configure GCC to include header files automatically?

I am trying to write a code which displays the roots of a given quadratic equation and for that i need the 'math.h' header file so I can use the 'sqrt()' function, but whenever I try to run the code it seems to not include the 'math.h' header file.…
0
votes
1 answer

analyze array in a specific direction

I have a dynamically allocated array that contains data for a piece of land: 0| 1| 2| 3| 4| 5| ->coordinates 0| 1 0 8 4 1 1 1| 7 4 2 6 7 8 2| 7 4 2 4 3 4 3| 7 1 6 2 0 8 4| 0 0 3 3 6 6 The numbers inside…
Moe
  • 17
  • 7
0
votes
1 answer

unexpected behavior of abs(unsigned)

i just stumbled upon a really crazy bug after over a year since writing a program (it hit an assertion) regarding abs(). i'll spare you the details and i'll just show you what i don't understand here: gcc version 7.5.0 on xubuntu_x64: #include…
Gyll
  • 351
  • 2
  • 6
0
votes
0 answers

CLion: Can't include Math.h

This is my CMakeLists.txt: cmake_minimum_required(VERSION 3.17) project(fms C) set(CMAKE_C_STANDARD 99) add_executable(fms main.c fms.c fms.h fms_data.c) target_link_libraries(fms m) The following is one of the compiler…
0
votes
0 answers

Round function in math.h is giving an incorrect output

#include #include int main(void) { printf("%f", round((27 + 28 + 28)/3)); } The roundoff is 28 but it is giving an output of 27. Please help
rktejesh
  • 70
  • 1
  • 9
0
votes
0 answers

Why can't use variables when calling log function?

I found a very strange thing. When I use the log function in the math.h library, I cannot use variables. #include #include int main(){ int b=100; double a = log10(100)/log10(10); printf("%lf",a); return 0; } The…
Gerrie
  • 736
  • 3
  • 18
0
votes
0 answers

undefined reference to sin and exp in c

I am trying to compile a bunch of different object files into an executable file using this command: gcc -Wall -Ilib -lm -Itest/lib -o test/test_passwd test/test_cases/test_passwd.c build/tests/hills_quad_two.o build/tests/hills_blank_quad.o…
0
votes
1 answer

Facing problem with a specific input using pow()

#include #include int main() { int n, num, sum=0, count=0, a, remain=0; printf("Enter a number : "); scanf("%d", &num); a=num; n=num; while(a!=0) { a=a/10; count++; } …
0
votes
1 answer

Is there a reverse to Modulus in C

It's been over thirty years since my high-school algebra so pardon my ignorance due to senility. Is there a inverse to modulus in C language. Such that one could solve the reverse of a previous statement called. Quite simply : x = y % 128 How do I…
Whales
  • 11
  • 1
0
votes
1 answer

Trying to calculate sin function using a number that is inputted from the user using thread

I am trying to write a C program which involves threads. The user inputs a number and a thread is created to compute the sin value for that number. Right now when I compile and run the code the thread never seems to terminate. I have also included…
0
votes
1 answer

Why is the C rand() function returning the same sequence every time?

I've recently written a little program to test the C rand function found in . I've compiled it twice and run it multiple times. On every run, the same output was printed out: 2 2 6 3 5 3 Can someone point out the problem? Here is the…
Serket
  • 3,785
  • 3
  • 14
  • 45
0
votes
1 answer

Need to use extra option while compiling c code which includes

Whenever I include math.h to my c code I can't compile without the -lm option. I get this error message: d.o: In function `refresh_position': d.c:(.text+0x4df): undefined reference to `sqrt' d.c:(.text+0x524): undefined reference to `sqrt' collect2:…
Baran
  • 131
  • 8