cmath Questions

6

Solved

I'm trying to allow my program to round a number up and down respectively. For example, if the number is 3.6, my program is suppose to round up the nearest number which is 4 and if the number is ...
Karyogamy asked 7/10, 2016 at 20:7

2

Solved

I want to compute a lookup table at compile time for a mathematical function in a given range and then retrieve values from the table at run time. My code is as follows: #include <iostream> ...
Samphire asked 8/4, 2016 at 10:42

3

I'm compiling my project with clang but I'm having an odd error: [ 1%] Building CXX object CMakeFiles/tfs.dir/src/actions.cpp.o In file included from /home/travis/build/dominique120/miniature-adve...
Intersperse asked 31/3, 2014 at 0:54

4

Solved

In my unmanaged C++ source i have: #define _USE_MATH_DEFINES #include <cmath> and then I use M_PI a couple of times. Compiling in Debug configuration works flawlessly but in Release it giv...
Pert asked 2/11, 2010 at 12:8

2

Solved

I'd like to understand the behavior of the following code, from the C++ Standard point of view (GCC 9.3, C++20): #include <cstdlib> template<class> struct type_tester; int main()...
Peacetime asked 21/2, 2022 at 11:32

5

Solved

I'm running a simple C++ program from HackerRank about pointers and it works fine on the website. However, when I run it on MacOS, I get error: call to 'abs' is ambiguous and I'm not sure exactly w...
Rydder asked 10/7, 2019 at 20:43

1

I have a simple C++ program that imports cmath. #include <cmath> int main() { return 0; } I'm trying to compile it using the following command. clang++ -o test main.cpp -std=c++14 But...
Rotorua asked 15/4, 2020 at 19:12

7

Solved

Are there any definitions of functions like sqrt(), sin(), cos(), tan(), log(), exp() (these from math.h/cmath) available ? I just wanted to know how do they work.
Dutybound asked 27/12, 2010 at 19:10

1

Solved

I got variable named y0 and included cmath, when compiling it with g++ without any args, I get a compilation error error: invalid operands of types ‘double(double) throw ()’ and ‘double’ to binary...
Nonconcurrence asked 28/11, 2019 at 15:56

4

I have the following C++ code: #include <math.h> #include <cmath.h> // per http://www.cplusplus.com/reference/clibrary/cmath/abs/ // snip ... if ( (loan_balance < 0) && (a...
Eraser asked 3/9, 2009 at 15:13

2

Solved

I've recently run into an issue where I got a segfault in MSVC where I wouldn't in GCC. After hours I realized that apparently my version of MSVC does not support the following syntax: double va...
Zolner asked 20/5, 2019 at 14:33

2

Solved

The page https://en.cppreference.com/w/cpp/numeric/math/fabs mentions that std::fabsf is available since C++11. However, when I use G++ 6.3.0 to compile even the simplest program that uses std::fab...
Selfcongratulation asked 3/1, 2019 at 18:18

3

Solved

I have a custom data type that in practice can be either float or double. On every OS except OSX, I am able to successfully build this C++11 template: #include <cmath> #include <cstdlib&g...
Merril asked 6/5, 2015 at 18:16

4

Solved

Test code: #include <cmath> #include <cstdio> const int N = 4096; const float PI = 3.1415926535897932384626; float cosine[N][N]; float sine[N][N]; int main() { printf("a\n"); for ...
Tormentor asked 7/8, 2011 at 23:17

7

Solved

Many algorithms require to compute (-1)^n (both integer), usually as a factor in a series. That is, a factor that is -1 for odd n and 1 for even n. In a C++ environment, one often sees: #include&l...
Delicatessen asked 17/3, 2015 at 22:14

3

Solved

So noticed from this page that none of the math functions in c++11 seems to make use of constexpr, whereas I believe all of them could be. So that leaves me with two questions, one is why did they ...
Proctology asked 27/6, 2013 at 16:0

2

Solved

Here is some code: #include <iostream> #include <cmath> using namespace std; int main() { long long int a, b; long long int c; cin >> a >> b; c = abs(a) + abs(b); ...
Insulation asked 12/8, 2017 at 15:14

4

Solved

I assume that abs and fabs are behaving different when using math.h. But when I use just cmath and std::abs, do I have to use std::fabs or fabs? Or isn't this defined?
Siu asked 25/6, 2010 at 13:2

1

Solved

I was surprised by the number of C++ facilities to represent quiet NaN value. I found three standard ways: std::numeric_limits<T>::quiet_NaN() - generic, and I thought it was the chosen one...
Anthracite asked 4/2, 2017 at 20:55

2

Solved

I've been working on a few project Euler exercises to improve my knowledge of C++. I've written the following function: int a = 0,b = 0,c = 0; for (a = 1; a <= SUMTOTAL; a++) { for (b = a+1;...
Caddoan asked 10/12, 2016 at 6:19

3

Solved

I have here a small test app which uses isnan from <math.h>: #include <iostream> #include <math.h> int main() { double d = NAN; std::cout << isnan(d) << '\n'; re...
Subequatorial asked 24/8, 2016 at 17:56

4

Solved

I used to work with math.h without any problem. Now, I use an external library which itself has a file called math.h, but which includes < cmath>. Adding this library to my project (or even j...
Dagda asked 21/10, 2010 at 0:51

3

Solved

I am sure this is a really stupid question, but when I pass an angle of 180 degrees into c/c++'s cos() and sin() functions I appear to receive an incorrect value. I know that it should be: sin of 0...
Spue asked 19/7, 2015 at 14:14

4

Solved

Since isnan can be either a macro (in C++98) or a function defined in namespace std (in C++11), an obvious (and possibly naive) way to write the code that works in both cases is illustrated by this...
Metalliferous asked 18/11, 2015 at 1:42

3

Solved

I checked the difference between abs and fabs on python here As I understand there are some difference regarding the speed and the passed types, but my question related to native c++ on V.S. Rega...
Triumvirate asked 16/11, 2015 at 15:7

© 2022 - 2025 — McMap. All rights reserved.