Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

22.8. Advice

  1. Numerical problems are often subtle. If you are not 100% certain about the mathematical aspects of a numerical problem, either take expert advice or experiment; §22.1.

  2. Use numeric_limits to determine properties of built-in types; §22.2.

  3. Specialize numeric_limits for user-defined scalar types; §22.2.

  4. Use valarray for numeric computation when run-time efficiency is more important than flexibility with respect to operations and element types; §22.4.

  5. Express operations on part of an array in terms of slices rather than loops; §22.4.6.

  6. Use compositors to gain efficiency through elimination of temporaries and better algorithms; §22.4.7.

  7. Use std::complex for complex arithmetic; §22.5.

  8. You can convert old code that uses a complex class to use the std:: complex template by using a typedef; §22.5.

  9. Consider accumulate(), inner_product(), partial_sum(), and adjacent_difference() before you write a loop to compute a value from a list; §22.6.

  10. Prefer a random-number class for a particular distribution over direct use of rand(); §22.7.

  11. Be careful that your random numbers are sufficiently random; §22.7.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial