1#! /bin/bash -e 2# ----------------------------------------------------------------------------- 3# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell 4# 5# CppAD is distributed under the terms of the 6# Eclipse Public License Version 2.0. 7# 8# This Source Code may also be made available under the following 9# Secondary License when the conditions for such availability set forth 10# in the Eclipse Public License, Version 2.0 are satisfied: 11# GNU General Public License, Version 2.0 or later. 12# ----------------------------------------------------------------------------- 13echo_eval() { 14 echo $* 15 eval $* 16} 17# ----------------------------------------------- 18echo "create gcc_complex.cpp" 19cat << EOF > gcc_complex.cpp 20# include <complex> 21# include <iostream> 22# include <limits> 23 24int main(void) 25{ double inf = std::numeric_limits<double>::infinity(); 26 std::complex<double> c_inf( inf ); 27 std::complex<double> c_1( 1. ); 28 29 std::cout << "c_inf = " << c_inf << std::endl; 30 std::cout << "c_1 = " << c_1 << std::endl; 31 std::cout << "c_inf / c1 = " << c_inf / c_1 << std::endl; 32 33 return 0; 34} 35EOF 36echo_eval g++ gcc_complex.cpp -o gcc_complex 37echo_eval ./gcc_complex 38cat << EOF 39Explination: 40 41(x + i*y) (x + i*y) * (a - i*b) (x*a - y*b) + i*(y*a - x*b) 42--------- = --------------------- = --------------------------- 43(a + i*b) (a + i*b) * (a - i*b) a*a + b*b 44 45In our case x = inf, y = 0, a = 1, b = 0, so we have 46 47(x + i*y) (inf*1 - 0*0) + i*(0*1 - inf*0) 48--------- = ------------------------------ = inf - i*nan 49(a + i*b) 1*1 + 0*0 50EOF 51echo_eval rm gcc_complex.cpp gcc_complex 52