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

Unexpected output math.h

Does anybody knows why this code prints 1000000000000000000 and not 1000000000000000001 as expected? #include #include int main(void){ long long n = (pow(10,18) + 1); printf("%lld ", n); }
Gendozz
  • 83
  • 5
1
vote
1 answer

what does Format specifier int* & double* warning message mean?

My program is to get (a^b)%c . my program - #include #include double powfunction (double x, double y) { double answer = pow(x,y); return answer; } int main() { int t, result, c, asign; double a, b; …
user15801453
1
vote
2 answers

Pow function in C is outputting zero

I'm writing an integration script, and it uses a non-uniform grid. I'm using the pow function in math.h to calculate by what each value of x should be multiplied to get to the next value of x (this value is xmult in my code). However, for some…
walale12
  • 13
  • 3
1
vote
1 answer

Undefined reference to log10?

I have the following two functions and when compiling, I am face with the error in the title. double getIdf(FileList fl, int D){ double fileCount = countFiles(fl); //todo countfiles double temp = fileCount/D; double idf = log10(temp); return…
REDBEAN
  • 21
  • 5
1
vote
2 answers

Setting up Exponential growth function X = a(1+b)^t in C language

I'm writing a program to track the number of rectangles being made in one week using the exponential growth function (X = a(1+b)^t). One person can make 60 rectangles per day. a represents the initial population, this is the number of people already…
Kakarotto
  • 65
  • 7
1
vote
1 answer

How to draw circle with sin and cos in C?

I have a problem about make some circle orbit (solar system stimulation) in C. Actually, I did it about a day. but I can't figure it out. First, how to change the planets movement speed? Some friends told me that I can use "If" for speed arrange,…
Kihyeon Kim
  • 23
  • 1
  • 5
1
vote
2 answers

Standard C library linker issues while compiling and linking using ARM Compiler 6

I am facing some linker issues in ARM DS IDE, i am trying build code for ARMVv-8 architecture, Cortex A72 processor with ARM Compiler 6. I think those error are related to standard libraries like stdio.h ,math.h these errors should not come as…
nilesh
  • 55
  • 10
1
vote
1 answer

How do you use Golang's cgo with C libraries that link to math.h?

I'm currently trying to build a Golang wrapper for the NOVAS C package (an astrometry/astronomy package) by using cgo. NOVAS is essentially 'installed' by placing the source files in whatever directory you happen to be working in (no compiled…
jos
  • 149
  • 9
1
vote
3 answers

How is attributing a double to an int even possible in this case?

I just started learning C and I'm having trouble understanding why the following code even works at all: void convertMyNumber (float myValue) { int myNewValue = floor(myValue * 100); printf("%d", myNewValue); } Looking at the documentation…
1
vote
1 answer

undefined reference to a function, which has already been linked

I am making a C program called reporter, here is the include: #include #include #include #include This is where the problem happened: Stats_dump(stats); Stats_dump in Stats.c(implementation…
Van Teo Le
  • 164
  • 3
  • 11
1
vote
1 answer

Creating rational number from float gives imprecise results

I am training my C skills. I was doing a function that receives a float number and was supposed to return a fraction that I did with struct. When I was trying to round down the number, I started to see some weird results. I suspect that is some…
1
vote
4 answers

Why const correctness rule doesn't work for built in libraries?

There is a rule about const methods. If the method is const, and we are trying to use another function at the same method, so it should be const as well. Otherwise, we will have a compilation error. I was trying to find the declaration of abs()…
1
vote
1 answer

How can I print out the perimeter and the number of right-angled triangle with a given range?

The question need the user input two value, P and Q. The program then will output the number of right angle integer triangle as well as its perimeter from P to Q. For example: Input: 154 180 Output: 154 1 156 1 160 1 168 3 176 1 180 3 I think i…
eulerisgod
  • 135
  • 6
1
vote
4 answers

M_PI Imprecision

I'm trying to printf M_PI but i think i'm not using the correct format specifier. The output should be: 3.14159265358979323846 but i get 3.14159265358979300000. int main(void) { printf("%.20f\n", M_PI); return 0; } I've tried using %Lf,…
qwerty000
  • 176
  • 11
1
vote
1 answer

How do I use ilogb with newLib?

I am using a stm32 which uses GNU Arm Embedded Toolchain which uses the newLib. I added some the skeletons from asn1c and run into a linker problem when using floats. The Linker error says: undefined reference to `ilogb' It seems to me that newLib…
eDeviser
  • 1,605
  • 2
  • 17
  • 44