cmath

What to do if tgamma() function is not defined?

空扰寡人 提交于 2019-12-12 03:57:15
问题 I am trying to use tgamma() from the standard library. When I try to compile, I get the error message: Call to undefined function tgamma I have the directive #include <cmath> . I use Embarcadero C++ Builder XE3, which claims to support C++11 standards. What could be my problem, and how to fix it? 回答1: Boost contains a tgamma function. #include <boost/math/special_functions/gamma.hpp> ... double rootPi = boost::math::tgamma<double>(0.5); Of course, you can always switch to a different compiler

Are cmath exp() and log() functions always symmetrical?

爱⌒轻易说出口 提交于 2019-12-11 20:35:39
问题 Are cmath exp() and log() functions always symmetrical? Ergo if I do double x; double y = exp(log(x)); assert(x == y); will the assert ever fail, and in that case: under what circumstances? We can assume that x is a rational number > 0 . 回答1: A floating-point log cannot be one-to-one. It needs to be monotone increasing and satisfy log(64) > 4.15 and log(128) < 4.86 . There are 2 52 double s between 64 and 128, but there are fewer than 2 50 double s between 4.15 and 4.86. There are multiple

FFT wrong value?

心已入冬 提交于 2019-12-11 19:40:02
问题 Randomly building a very easy sound spectrum analyzer. Given this python code: http://rosettacode.org/wiki/Fast_Fourier_transform#Python Implemented like this: import math from cmath import exp, pi def fft(x): N = len(x) if N <= 1: return x even = fft(x[0::2]) odd = fft(x[1::2]) return ([even[k] + exp(-2j * pi * k / N) * odd[k] for k in xrange(N / 2)] + [even[k] - exp(-2j * pi * k / N) * odd[k] for k in xrange(N / 2)]) #res = fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]) res = [math.sin(k) /

What is the complexity / real cost of exp in cmath compared to a FLOP?

我怕爱的太早我们不能终老 提交于 2019-12-11 13:50:58
问题 [I globally edited the question to be more "useful" and clear] I was wondering about the complexity of the implementation of the function exp in cmath. By complexity, I mean algorithmic complexity if possible. Otherwise cost compared to a floating point operation (addition for example) The following lines : double x = 3; double y = std::exp(x); compile to : ... 19,23d16 movq %rax, -40(%rbp) movsd -40(%rbp), %xmm0 call exp movsd %xmm0, -40(%rbp) movq -40(%rbp), %rax ... exp has to be

cmath functions generating compiler error

放肆的年华 提交于 2019-12-11 05:59:39
问题 I've written a small program that utilizes the Fast Light Toolkit and for some reason a compiler error is generated when trying to access the functions in the cmath header. Such as error ::acos has not been declared. This goes on for pretty much every function it tries to use in the header. What could I be missing? The header files I have included are Simple_window.h Graph.h both of which are part of the FLTK. The code is this: #include "Simple_window.h" // get access to our windows library

FFT unexpected frequency shift after window function application

走远了吗. 提交于 2019-12-11 03:28:36
问题 I got this python code for FFT calculation of a sound signal: from math import * from cmath import exp, pi def fft(x): N = len(x) if N <= 1: return x even = fft(x[0::2]) odd = fft(x[1::2]) return ([even[k] + exp(-2j * pi * k / N) * odd[k] for k in xrange(N / 2)] + [even[k] - exp(-2j * pi * k / N) * odd[k] for k in xrange(N / 2)]) N = 64 res = [sin(k) for k in xrange(N)] # Window function a = 2*pi/(N-1) for k in xrange(N): z = a * res[k] res[k] = 0.42659 - 0.49656*cos(z) + 0.076849*cos(2*z)

What is the definition for gamma(double x) and why is it different on two gcc versions?

让人想犯罪 __ 提交于 2019-12-11 02:54:30
问题 Through unfortunate circumstances I have discovered that my standard library implementations <math.h> and <cmath> (C++) apparently contain a definition for a function with a prototype like: double gamma(double x); Though I do not see it listed anywhere in the language standard (draft I have access to). Using gcc v4.2.1 on Mac OS X that function evaluates the same as tgamma which is actually the name given to it in the standard. (reference) But on gcc v4.6.3 on Ubuntu 12.04 that function

What's the difference between abs and fabs?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 14:14:42
问题 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. Regarding the V.S. I tried the following on Visual Studio 2013 (v120) : float f1= abs(-9.2); // f = 9.2 float f2= fabs(-9); // Compile error [*] So fabs(-9) it will give me a compiler error, but when I tried to do the following: double i = -9; float f2= fabs(i); // This will work fine What I understand

Template version of std::abs

柔情痞子 提交于 2019-12-08 14:29:53
问题 Here lists the current overloads of std::abs in C++. I'm wondering why not just define the following template and let go all the ugly C-style overloads? template <typename T> inline T abs(const T& v) { return v < 0 ? -v : v; } 回答1: See LWG issue 2192. Currently, std::abs(x-y) < 2 fails if x and y are unsigned. This catches a subtle programming error. With the proposed change, it compiles but does entirely the wrong this. abs(3u-4u) would be much larger than 2, in fact it's UINT_MAX . 回答2:

Disable math.h crap when working with cmath [duplicate]

爱⌒轻易说出口 提交于 2019-12-07 11:17:35
问题 This question already has answers here : cmath header confusion (4 answers) Closed 6 years ago . I had a problem previously because of functions being overloaded without std:: . And the curse is still happening every now and then because I don't use using namespace std; . Removing using namespace std causes the program to get crap results Is there a way to disable all those non-std functions that come from c and only work with c++ functions under the namespace std (without having to use using