On Fri, Jun 3, 2011 at 11:14 PM, Bryan Hundven <bryanhundven@xxxxxxxxx> wrote: > On Fri, Jun 3, 2011 at 9:47 PM, eric <fsshl@xxxxxxx> wrote: >> Dear Steve Oualline: >> Âthe book (Practical C++ Programming), AppendixD >> computing sine using a power series >> the program you listed on page 525, Example D-2 sin/sine.cpp >> I tested on my linux/gnu-g++ >> ---------------- >> eric@eric-laptop:~/practicalCpp/sin$ ./sine 3.141 >> x**1   3.141E+00 >> 1!    1.000E+00 >> x**1/1! 3.141E+00 >> Âtotal  3.141E+00 >> >> x**3   3.099E+01 >> 3!    6.000E+00 >> x**3/3! 5.165E+00 >> *** stack smashing detected ***: ./sine terminated >> ======= Backtrace: ========= >> /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x50)[0x3d8390] >> /lib/tls/i686/cmov/libc.so.6(+0xe233a)[0x3d833a] >> ./sine[0x8048e11] >> ./sine[0x8048bb5] >> /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x30cbd6] >> ./sine[0x80488b1] >> ======= Memory map: ======== >> 00110000-00134000 r-xp 00000000 08:01 >> 8913271  Â/lib/tls/i686/cmov/libm-2.11.1.so >> 00134000-00135000 r--p 00023000 08:01 >> 8913271  Â/lib/tls/i686/cmov/libm-2.11.1.so >> 00135000-00136000 rw-p 00024000 08:01 >> 8913271  Â/lib/tls/i686/cmov/libm-2.11.1.so >> 0025b000-00276000 r-xp 00000000 08:01 8913086  Â/lib/ld-2.11.1.so >> 00276000-00277000 r--p 0001a000 08:01 8913086  Â/lib/ld-2.11.1.so >> 00277000-00278000 rw-p 0001b000 08:01 8913086  Â/lib/ld-2.11.1.so >> 002d7000-002f4000 r-xp 00000000 08:01 8912979  Â/lib/libgcc_s.so.1 >> 002f4000-002f5000 r--p 0001c000 08:01 8912979  Â/lib/libgcc_s.so.1 >> 002f5000-002f6000 rw-p 0001d000 08:01 8912979  Â/lib/libgcc_s.so.1 >> 002f6000-00449000 r-xp 00000000 08:01 >> 8913215  Â/lib/tls/i686/cmov/libc-2.11.1.so >> 00449000-0044a000 ---p 00153000 08:01 >> 8913215  Â/lib/tls/i686/cmov/libc-2.11.1.so >> 0044a000-0044c000 r--p 00153000 08:01 >> 8913215  Â/lib/tls/i686/cmov/libc-2.11.1.so >> 0044c000-0044d000 rw-p 00155000 08:01 >> 8913215  Â/lib/tls/i686/cmov/libc-2.11.1.so >> 0044d000-00450000 rw-p 00000000 00:00 0 >> 00988000-00989000 r-xp 00000000 00:00 0     Â[vdso] >> 0099a000-00a83000 r-xp 00000000 08:01 12062387  /usr/lib/libstdc >> ++.so.6.0.13 >> 00a83000-00a84000 ---p 000e9000 08:01 12062387  /usr/lib/libstdc >> ++.so.6.0.13 >> 00a84000-00a88000 r--p 000e9000 08:01 12062387  /usr/lib/libstdc >> ++.so.6.0.13 >> 00a88000-00a89000 rw-p 000ed000 08:01 12062387  /usr/lib/libstdc >> ++.so.6.0.13 >> 00a89000-00a90000 rw-p 00000000 00:00 0 >> 08048000-0804a000 r-xp 00000000 08:01 >> 5507048  Â/home/eric/practicalCpp/sin/sine >> 0804a000-0804b000 r--p 00001000 08:01 >> 5507048  Â/home/eric/practicalCpp/sin/sine >> 0804b000-0804c000 rw-p 00002000 08:01 >> 5507048  Â/home/eric/practicalCpp/sin/sine >> 08b07000-08b28000 rw-p 00000000 00:00 0     Â[heap] >> b78bf000-b78c1000 rw-p 00000000 00:00 0 >> b78d5000-b78d8000 rw-p 00000000 00:00 0 >> bfc8f000-bfca4000 rw-p 00000000 00:00 0     Â[stack] >> Aborted >> eric@eric-laptop:~/practicalCpp/sin$ >> ------------------------------------------- >> that certainly is not what your book predict on page 523 >> plz help, Eric, US citizen >> >> > > Eric, > > Some of us don't have the book you reference, but if you post the > code, you might get more help. > > -Bryan > Eric, Actually, sorry. I just found the example code on the o'reilly site. I compiled and ran it... works for me. bryan@fling:~/cpp/sin$ uname -a Linux fling 2.6.38-9-generic #43-Ubuntu SMP Thu Apr 28 15:23:06 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux bryan@fling:~/cpp/sin$ gcc --version gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. bryan@fling:~/cpp/sin$ make -f makefile.gnu g++ -g -Wall -o sine sine.cpp -lm bryan@fling:~/cpp/sin$ ./sine 3.141 x**1 3.141E+00 1! 1.000E+00 x**1/1! 3.141E+00 total 3.141E+00 x**3 3.099E+01 3! 6.000E+00 x**3/3! 5.165E+00 total -2.024E+00 x**5 3.057E+02 5! 1.200E+02 x**5/5! 2.548E+00 total 5.239E-01 x**7 3.016E+03 7! 5.040E+03 x**7/7! 5.985E-01 total -7.457E-02 x**9 2.976E+04 9! 3.629E+05 x**9/9! 8.201E-02 total 7.438E-03 x**11 2.936E+05 11! 3.992E+07 x**11/11! 7.355E-03 total 8.300E-05 x**13 2.897E+06 13! 6.227E+09 x**13/13! 4.652E-04 total 5.482E-04 x**15 2.858E+07 15! 1.308E+12 x**15/15! 2.185E-05 total 5.263E-04 x**17 2.819E+08 17! 3.557E+14 x**17/17! 7.927E-07 total 5.271E-04 x**19 2.782E+09 19! 1.217E+17 x**19/19! 2.287E-08 total 5.271E-04 x**21 2.744E+10 21! 5.109E+19 x**21/21! 5.371E-10 11 term computed sin(3.141E+00)= 5.271E-04 Actual sin(3.141)=0.000592654 bryan@fling:~/cpp/sin$ Maybe take a look at the makefile.gnu from the examples: http://examples.oreilly.com/9780596004194/ -Bryan