[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
round-off error in std::pow(std::complex<T>, double) in C++11
From: |
Jordi Gutiérrez Hermoso |
Subject: |
round-off error in std::pow(std::complex<T>, double) in C++11 |
Date: |
Wed, 23 Jan 2013 10:07:03 -0500 |
Greetings, fellow GNU hackers.
Consider the following program,
#include <iostream>
#include <iomanip>
#include <cmath>
#include <complex>
int main(){
using namespace std;
cout << setprecision(16) << pow(complex<double>(0,1), 2) << endl;
}
Compile it with and without -std=c++0x:
address@hidden:~$ g++ foo.c++ -o foo && ./foo
(-1,0)
address@hidden:~$ g++ foo.c++ -o foo -std=c++0x && ./foo
(-1,1.224646799147353e-16)
The round-off error introduced by C++11 is partly due to the following
discussion:
http://stackoverflow.com/questions/5627030/why-was-stdpowdouble-int-removed-from-c11
For some reason, the pow(complex<T>, int) overload seems to be
missing in C++11, but it doesn't seem like the standard says it should
be. Can it be restored in GNU libstdc++ for C++11?
We ran into this in GNU Octave when our test suite reported round-off
errors when compiling with C++11:
https://savannah.gnu.org/bugs/?38142
http://octave.1599824.n4.nabble.com/Welcome-C-11-td4647840.html#a4647903
Thanks,
- Jordi G. H.
- round-off error in std::pow(std::complex<T>, double) in C++11,
Jordi Gutiérrez Hermoso <=
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Marc Glisse, 2013/01/23
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Jordi Gutiérrez Hermoso, 2013/01/23
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Marc Glisse, 2013/01/23
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Gabriel Dos Reis, 2013/01/24
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Ed Meyer, 2013/01/24
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Gabriel Dos Reis, 2013/01/24
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Jordi Gutiérrez Hermoso, 2013/01/25
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Marc Glisse, 2013/01/25
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Paolo Carlini, 2013/01/25
- Re: round-off error in std::pow(std::complex<T>, double) in C++11, Paolo Carlini, 2013/01/25