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

math.h methods working different?

I've tried some calculations on c, my code is below #include #include int main(void) { float a = 1.8; float b = 3.3; float c = 1.5; float d = 5.9; float e = 2.6; float result = a / (a + (abs(a - b) / (b +…
Cem Sönmez
  • 506
  • 1
  • 3
  • 15
-1
votes
1 answer

How to get 0.9 instead of 0

I am having a simple problem i want to get value after decimal points,Here is my code, float result = slotSize/60;//slot size is int and 57 I want result 0.95 ,but i am getting 0,please help me.I tried ceil value method but it gives 1 and floor…
-1
votes
1 answer

nan when executing printf

When I execute program #include #include #include double exponential(double u); double exponential(double u) { double a = (double)rand(); return (-u * log(1.0 - a)); } int main(void) { …
Germano Massullo
  • 2,572
  • 11
  • 40
  • 55
-1
votes
4 answers

Function to get minimum of three or more arguments

In the library in C, the function fmin(x,y) returns the minimum value of the two arguments x and y, as documented for instance in the C++ reference. However, is there a similar function fminimum(a,b,c,...x,y,z) available that finds the…
seb
  • 2,251
  • 9
  • 30
  • 44
-1
votes
1 answer

how to use clang compile c file with math.h?

#include #include int main() { printf("%.81f\n", 1+2*sqrt(3)/(5-0.1)); return 0; } output: /tmp/a4-4oU730.o: In function main': a4.c:(.text+0x4f): undefined reference tosqrt' clang: error: linker command failed with exit…
sakuya.luo
  • 31
  • 1
  • 2
-1
votes
4 answers

Calling functions from within function(float *VeryBigArray,long SizeofArray) from within objC method fails with EXC_BAD_ACCESS

Ok I finally found the problem. It was inside the C function(CarbonTuner2) not the objC method. I was creating inside the function an array of the same size as the file size so if the filesize was big it created a really big array and my guess is…
yan bellavance
  • 4,710
  • 20
  • 62
  • 93
-2
votes
2 answers

Fmod does not work as expected(c programming)

(the problem is caused by me and has been solved ,greetings from the newbie)I apologize to everyone, my function type was integer i just realized it, I opened it because I worked for hours, I have to delete it). I am using gcc 9.3.0 version and…
-2
votes
2 answers

C sqrt not working properly on floating point numbers below 1 but above 0

I am trying to create a vector with random dimensions, but with a magnitude of 1. This is what I've come up with (removed the rand() function and replaced it with a number common to both pieces of code.): float x = sqrt((4566%100)/100.f); float…
Serket
  • 3,785
  • 3
  • 14
  • 45
-2
votes
3 answers

How to include and use math.h library in cs50 ide

I had tried running a program which I solved in codeblocks and using math.h library in cs50 ide by Harvard University(which is Ubuntu based). Its giving me an error that library is not included. How to include to my cs50 ide..?
-2
votes
2 answers

c integer division not returning correct quotient

my code (in the C language) is this: avg = round((r + g + b) / 3); r = avg; g = avg; b = avg; It should do the grayscale image effect. There are no syntax errors, but apparently avg, when calculated as shown above with values r as 27, and both g…
person the human
  • 345
  • 4
  • 15
-2
votes
3 answers

Trying to Approximate Euler's number in C

I am trying to approximate Euler's number using the formula (1+(1/n))^n. The compiler is telling me that there is an "expected expression before 'double'" Here is the code: #include #include int main() { int x, y, power; …
-2
votes
1 answer

Including Math.h results in errors in cmath

In my includes I used #include , but when I attempt to compile and run the program it gives me a long list of syntax errors. Visual studio tells me the errors are in the file cmath, which I did not include nor use in the program Program works…
Sudoadmin
  • 35
  • 2
  • 8
-2
votes
1 answer

How To Add header in CLion

I'm New to CLion. I have created a project which name is test12 and which file name is avs.c. I'm Getting an Error of type Undefined reference 'sqrt' CMakeListsta.txt is : cmake_minimum_required(VERSION 3.13) project (test12 C) set(CMAKE_C_STANDARD…
karthik oggu
  • 35
  • 11
-2
votes
1 answer

C math.h wrong result

I was struggling to understand why the following snippet calculating information wrong: result = sqrt(5/8 + sqrt(5)/8); printf("Result is %1.15Lf\n", result); I tried to separate and calculate one part first and than another, and still having same…
Venny
  • 1
  • 2
-2
votes
4 answers

Pow() function in C

Here is the code that I couldn't figure out why it's not working (I'm always getting a result like 0.000000): #include #include int main () { double num,b; printf("Write a number between 0 and 256"); scanf("%lf",&num); …
Ut.Son
  • 9
  • 1
1 2 3
20
21