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

Including files in C

I want to make a simple function involving sqrt(), floor() and pow(). So, I included . When I try to use my function, my program says that sqrt() and floor() do not exist. I've triple checked my files and rewritten them, but it still gives…
-1
votes
1 answer

fstream stopping math.h from working

Possible Duplicate: cmath compilation error when compiling old C++ code in VS2010 Compilation fails in VS2010 for C++ programs building fine in Linux I am creating a program in C++ in which I need to read a text file in. I have included the…
CaptainProg
  • 5,610
  • 23
  • 71
  • 116
-1
votes
1 answer

Why pow() function working correctly, only after saving it to a variable?

I were asked to c-program to accept two variables and print the answer when second variable is raised to the power of first variable. So I coded, #include #include int x,y; int main() { scanf("%d…
-1
votes
1 answer

Is there a way to convert octal input to decimal/binary output without using math.h library and pow?

Beginner programmer here. Is there a way to input octal values and expect decimal or binary outputs without the use of functions or the math.h library? I have an idea of using a loop to achieve this but I haven't the faintest clue of how it should…
Lapnesnoj
  • 15
  • 4
-1
votes
1 answer

Different execution times between pow and powf of standard math.h library in c programming

I'm currently benchmarking several algorithms in C code. I recognized the following behavior I cannot explain: When comparing the execution times of the pow() and powf() function of the math.h library, executing the powf() function is two times…
Berni
  • 7
  • 2
-1
votes
1 answer

Problem compiling C progtam from command line gcc with math.h

I am new to the command line and I am trying to run a C program containing the function log10. If I give gcc -o -lm randomVamp random\ vampire.c I get the error gcc: error: randomVamp: No such file or directory but randomVamp is the name I wanted…
anotherOne
  • 1,513
  • 11
  • 20
-1
votes
1 answer

How do I solve this cmath compiler error?

Im fairly new to coding. I am doing a project with function calls, and my POW() and SQRT() functions say they're not declared in this scope. I'm not particularly sure how to solve this compiler error and appreciate any feedback #include…
Fiona
  • 1
  • 1
-1
votes
4 answers

Printing Armstrong numbers in C

This is a program to find Armstrong number between 1-1000 (Sum of cubes of each digit of the number equals the number itself).It is printing some of the numbers correctly however it is not printing 153. My question is that why the case 153 is…
yash gandhi
  • 45
  • 1
  • 5
-1
votes
1 answer

C++ sqrt function returning truncated (wrong) output

I have a doubt on the function sqrt of math.h I was debugging some code, and I figured out that my function was not working properly, as the square root of 2/3 was always returning zero. I tried to isolate the problem by just writing down some…
-1
votes
1 answer

M_PI_2 missing from clang on Windows

I make use of M_PI_2 from math.h in my source code. This works fine for my Linux, OSX, iOS and Android builds. When I use the clang compiler for Windows, I get: use of undeclared identifier 'M_PI_2' Why is there no M_PI_2 for my clang compiler on…
Bram
  • 7,440
  • 3
  • 52
  • 94
-1
votes
1 answer

The syntax for converting float value into the scientific notation in Arduino IDE?

I want to convert a float value to the scientific value, what's the syntax in Arduino IDE? for example, float f = 0.0032 in float should be print like 3.2x10^(-3) Serial.println(float2s(f, 7)); this syntax is not working in Arduino IDE. Please…
-1
votes
1 answer

Issue with fmod with doubles

It would seem fmod(x,1) where x is a double gives the wrong result, as output by the line: std::cout << fmod(min, 1) << "|" << fmod(max, 1) << std::endl; I forgot the name for what you call this, but this is the smallest amount of code necessary…
Jonathan Woollett-light
  • 2,813
  • 5
  • 30
  • 58
-1
votes
2 answers

Why use of sqrtf function from libgcc.a causes link double precision function?

I have problem with linking libgcc.a in my project. I need to use sqrtf and log10f, so I have added libgcc.a in makefile by add linker flag "-lm", math.h as include in module and everything compile great but something went wrong in my opinion. When…
Esato
  • 127
  • 1
  • 9
-1
votes
3 answers

Casting float to (int) in C - declaring cast (int) seems to have no effect

C program takes float value as command line argument, so need to format from string to float and then to integer. Using round() from math.h, and then want to cast to int. Casting by declaring (int) before value, but value type does not change.…
azochz
  • 1,006
  • 4
  • 12
  • 20
-1
votes
3 answers

Power function works wrong

printf("%d",pow(5,3)) it's printing 0, and works fine when number is different from 5 why? Can anyone explain this ?
Cool
  • 27
  • 1
  • 5