Skip to main content
Filter by
Sorted by
Tagged with
23 votes
4 answers
2k views

C23 added the classification macro iszero for testing whether an argument value is zero, specified like: int iszero(real-floating x); What is the difference between using iszero(x) and writing x == 0?...
Jan Schultke's user avatar
  • 44.4k
3 votes
2 answers
234 views

I am trying to solve a problem posed in this question which asks that a program be written that calculates logarithms of numbers without including <math.h>. I wrote the following program: #...
uran42's user avatar
  • 469
13 votes
4 answers
1k views

This question comes from an attempt to understand the "C philosophy" and not from any "real problem". Suppose that in a C program I use sin(x): #include <stdio.h> int main() ...
Arnab Chakraborty's user avatar
0 votes
2 answers
119 views

I read about C programming language in Yashwant Kanetkar's book Let us C. In Functions chapter I read about sin, cos, tan and pow functions of math.h file. But in this chapter it is written that: You ...
Abhinav Thakur's user avatar
3 votes
2 answers
141 views

Function frexp(3) returns the normalized mantissa xm of a double x, with a value in [0.5,1.0), unless x=0. So I can convert it to a long long as follows: int ie; // will be set in next line ...
Joachim W's user avatar
  • 8,457
0 votes
0 answers
44 views

I have a small C program: #include <stdio.h> #include <math.h> int main() { // this works printf("%lf", sin(3.14/2)); // this doesn't work float x = 3.14/2; ...
TheFibonacciEffect's user avatar
0 votes
1 answer
46 views

I have a problem with using log from math.h library on stm32f411ret6. when i pass a value normally to log eg. double var = log(2.0); than i get 0.69314718056 in var. When i pass a value using ...
dawid gurdzinski's user avatar
0 votes
1 answer
186 views

so my code ran smoothly in codium with the extensions when i was only working with stdio.h, but when i tried to use math.h module in my program i am unable to run it, this is what i get as error: ...
Suvansh Rao's user avatar
0 votes
3 answers
219 views

I wanted to know if there is any way of doing a variable in the power of another variable (or a constant) in C without using the math.h library. Like the operator ** in python for example. Trying to ...
Kfir Aizenman's user avatar
2 votes
1 answer
1k views

I have to implement my own version of the double cos(double x) function present in the <math.h> library of C. There are some things that I don't understand about the implementation of this ...
ramimamedov's user avatar
0 votes
0 answers
30 views

#include<stdio.h> #define _USE_MATH_DEFINES #include <math.h> void Multiply2Nos (float x, float y) { float result = x * y; printf("%.3f X %.3f = %.2f\n",x,y,result); } ...
Mohammed Atif's user avatar
0 votes
1 answer
69 views

I have written code in C to calculate the geometric series for three different cases. The values for the three cases are as follows. case 1: n=10000,a=2.0,r=0.01. Case 2: n=500,a=0.01,r=1.1. Case 3: n=...
Nick's user avatar
  • 401
0 votes
0 answers
76 views

I am writing a program in C which currently does the following: takes 4 coordinate pairs in the form (x,y) as input calculates the sides formed by two pairs of points, compares the corresponding ...
Nare Avetisyan's user avatar
1 vote
0 answers
68 views

I have an array of unsigned long long int type, the values are entered in one line through the console, among the numbers there are (2^32-1)^2-1 and (2^32-1)^2+1. How can I convert this to a natural ...
rvevau's user avatar
  • 63
-1 votes
2 answers
771 views

Task: In an array of N elements (N < 20) of the unsigned long long type find the maximal full square and print its index (starting from zero). If there are no full squares, print -1. If there is ...
rvevau's user avatar
  • 63
2 votes
1 answer
920 views

I was working on some C++ code to process video frame, and found std::fmin and std::fmax is much slower than simply conditional operator. I've simplify my code as following (modify my code more C++ ...
danry's user avatar
  • 89
-3 votes
1 answer
179 views

#include <stdio.h> #include <math.h> int i; double result = 0; int terms; int term; double stage1; double stage2; double zeta(int terms){ for (i=0; i != terms; i++){ result += ...
Yazan Ahmad's user avatar
0 votes
0 answers
66 views

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 ...
Eman's user avatar
  • 303
0 votes
2 answers
1k views

I've just installed Scilab 2023 in Windows 10 with Visual Studio Buildtools successfully: --> haveacompiler() ans = T --> findmsvccompiler() ans = "Visual Studio Build Tools 2022&...
Salva's user avatar
  • 1
0 votes
1 answer
312 views

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 ...
garej's user avatar
  • 575
1 vote
1 answer
731 views

Edited for test case and compiler inconsistency. Recently I made a change to use the more modern < cmath > instead of < math.h >. While this compiled just fine as expected with no warnings,...
Brinck's user avatar
  • 69
0 votes
0 answers
718 views

So, I'm trying to compile a simple C program in windows environment using GCC: #include <stdio.h> #include <math.h> int main(void) { printf("hi\n"); double x = sin(10); ...
Luguecos's user avatar
  • 341
0 votes
1 answer
93 views

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 -...
FN-2187's user avatar
0 votes
0 answers
541 views

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 ...
mohsen setodeh's user avatar
1 vote
2 answers
1k views

Im working on a project about active power and reactive power measurement kit with using PIC16F877A MCU. In the code, I use pow, sqrt and cos functions which are included in math.h library. when I ...
El_Canario's user avatar
1 vote
0 answers
1k views

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 ...
ysap's user avatar
  • 8,251
2 votes
1 answer
115 views

The erfcf(FLT_MAX) produces 0.0f and sets errno to ERANGE. The erff(FLT_MAX) produces 1.0f and does not set errno to ERANGE. In both cases returned results differ from the "true results" (i....
pmor's user avatar
  • 6,775
0 votes
2 answers
135 views

I am trying to use memset with INFINITY or NAN present in C header file <math.h> My code is: double *dist; dist = (double *)malloc(7*sizeof(double)); memset(dist, INFINITY, 7*sizeof(dist[0])); ...
Surya Majumder's user avatar
0 votes
1 answer
232 views

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 ...
Ivan Perez's user avatar
0 votes
0 answers
251 views

I'm using stm32f4xx mcu with <math.h> 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 ...
박동진's user avatar
0 votes
0 answers
23 views

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 <math.h> #...
MrGorbunov's user avatar
2 votes
4 answers
832 views

I was trying to write a program to calculate the value of x^n using a while loop: #include <stdio.h> #include <math.h> int main() { float x = 3, power = 1, copyx; int n = 22, copyn;...
Abir Mondal's user avatar
-1 votes
1 answer
100 views

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<stdio.h> #include<math.h> int x,...
ADHIROOBAN D's user avatar
1 vote
1 answer
3k views

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?
Mohamed AbdelAzeem's user avatar
1 vote
2 answers
227 views

I created a function to calculate the Euclidean distance between two points in C (written in the Codeblocks IDE), however some errors occurred: error: expected ')' before 'p1'| error: expected ...
Randy Chen's user avatar
0 votes
0 answers
42 views

I'm having trouble using the arcsine() function. When I use this code: #include <iostream> #include <math.h> using namespace std; int main() { cout << asin(12 / 13); } I get 0 ...
Galen Burnett's user avatar
1 vote
1 answer
74 views

Does anybody knows why this code prints 1000000000000000000 and not 1000000000000000001 as expected? #include <stdio.h> #include <math.h> int main(void){ long long n = (pow(10,18) + 1);...
Gendozz's user avatar
  • 93
-1 votes
1 answer
155 views

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 ...
Lapnesnoj's user avatar
0 votes
0 answers
44 views

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 <stdio.h> #include <math....
Infinity_hunter's user avatar
-1 votes
1 answer
282 views

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,...
Berni's user avatar
  • 7
4 votes
2 answers
305 views

If the next representable value after -0.0 is +0.0, then why nextafter(-0.0, INFINITY) does not return +0.0?
pmor's user avatar
  • 6,775
0 votes
3 answers
208 views

#include <stdio.h> #include <math.h> #include <stdlib.h> int main(void) { int i; double interval; for(i=0;i<30;i++) { interval = i/10.0; ...
Bishal Hazarika's user avatar
0 votes
0 answers
30 views

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 ...
Shreyas Gavhalkar's user avatar
0 votes
1 answer
50 views

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 ...
Moe's user avatar
  • 17
1 vote
1 answer
97 views

My program is to get (a^b)%c . my program - #include <stdio.h> #include <math.h> double powfunction (double x, double y) { double answer = pow(x,y); return answer; } int main() { ...
user avatar
-2 votes
2 answers
313 views

(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 ...
user15465584's user avatar
3 votes
1 answer
203 views

Why I am getting the following error /tmp/ccuWdVB3.o: In function `test': MyCode.c:(.text+0x1c): undefined reference to `sqrt' collect2: error: ld returned 1 exit status MyCode.c #include<stdio.h&...
Aayush Jain's user avatar
0 votes
1 answer
194 views

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: ...
Gyll's user avatar
  • 381
0 votes
0 answers
338 views

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 ...
Sublimibus's user avatar
-1 votes
1 answer
100 views

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 ...
anotherOne's user avatar
  • 1,661

1
2 3 4 5
7