{"id":592,"date":"2014-12-19T13:15:07","date_gmt":"2014-12-19T12:15:07","guid":{"rendered":"http:\/\/numbercrunch.de\/blog\/?p=592"},"modified":"2023-01-18T22:20:01","modified_gmt":"2023-01-18T21:20:01","slug":"c1114-for-scientific-computing-ii","status":"publish","type":"post","link":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/","title":{"rendered":"C++11\/14 for scientific computing II"},"content":{"rendered":"<h2>Complex numbers<\/h2>\n<p style=\"text-align: justify;\">The template class <code>std::complex<\/code> and functions for complex numbers (defined in the header file <code>complex<\/code>) have been extended in C++11\/14. The new function <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/numeric\/complex\/proj\"><code>std::proj<\/code><\/a> returns the projection of the complex number $z$ onto the Riemann sphere. The functions <code>std::asin<\/code>, <code>std::acos<\/code> and <code>std::atan<\/code> calculate the inverse of the sine, cosine and tangent for complex arguments and similarly <code>std::ahsin<\/code>, <code>std::ahcos<\/code> and <code>std::ahtan<\/code> compute the inverses of the complex hyperbolic trigonometric functions. The member functions <code>real<\/code> and <code>imag<\/code> are overloaded in C++11. In C++11 it is not only possible to get the real and the imaginary part of a complex number, the real and the imaginary may now also be set by these functions as illustrated below.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include &lt;iostream&gt;\n#include &lt;complex&gt;\n\nint main() {\n  std::complex&lt;double&gt; z;\n  \/\/ set real and imaginary part\n  z.real(1);\n  z.imag(2);\n  \/\/ get real and imaginary part\n  std::cout &lt;&lt; \"z = \" &lt;&lt; z.real() &lt;&lt; \" + \" &lt;&lt; z.imag() &lt;&lt; \"i\\n\";\n}\n<\/pre>\n<p style=\"text-align: justify;\">C++14 introduces the literals <code>if<\/code>, <code>i<\/code> and <code>id<\/code>, which represent pure imaginary numbers in single, double and extended precision, respectively. These literals are declared in the <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/namespace\">inline namespace<\/a> <code>std::literals::complex_literals<\/code> and make complex expressions in source code more easy to write and read as the following example shows.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include &lt;iostream&gt;\n#include &lt;complex&gt;\n\nint main() {\n  using namespace std::literals;\n  \n  double pi=std::acos(-1.);\n  std::complex&lt;double&gt; z=std::exp(1i*pi); \/\/ Euler's formula\n  std::cout &lt;&lt; \"exp(i, pi) = \" &lt;&lt; z &lt;&lt; '\\n';\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Complex numbers The template class std::complex and functions for complex numbers (defined in the header file complex) have been extended in C++11\/14. The new function std::proj returns the projection of the complex number $z$ onto the Riemann sphere. The functions std::asin, std::acos and std::atan calculate the inverse of the sine, cosine and tangent for complex&hellip; <a href=\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">C++11\/14 for scientific computing II<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-592","post","type-post","status-publish","format-standard","hentry","category-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++11\/14 for scientific computing II - Number Crunch<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++11\/14 for scientific computing II - Number Crunch\" \/>\n<meta property=\"og:description\" content=\"Complex numbers The template class std::complex and functions for complex numbers (defined in the header file complex) have been extended in C++11\/14. The new function std::proj returns the projection of the complex number $z$ onto the Riemann sphere. The functions std::asin, std::acos and std::atan calculate the inverse of the sine, cosine and tangent for complex&hellip; Continue reading C++11\/14 for scientific computing II\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\" \/>\n<meta property=\"og:site_name\" content=\"Number Crunch\" \/>\n<meta property=\"article:published_time\" content=\"2014-12-19T12:15:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-18T21:20:01+00:00\" \/>\n<meta name=\"author\" content=\"Heiko Bauke\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Heiko Bauke\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\"},\"author\":{\"name\":\"Heiko Bauke\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\"},\"headline\":\"C++11\/14 for scientific computing II\",\"datePublished\":\"2014-12-19T12:15:07+00:00\",\"dateModified\":\"2023-01-18T21:20:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\"},\"wordCount\":153,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\"},\"articleSection\":[\"C++\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\",\"url\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\",\"name\":\"C++11\/14 for scientific computing II - Number Crunch\",\"isPartOf\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#website\"},\"datePublished\":\"2014-12-19T12:15:07+00:00\",\"dateModified\":\"2023-01-18T21:20:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.numbercrunch.de\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++11\/14 for scientific computing II\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#website\",\"url\":\"https:\/\/www.numbercrunch.de\/blog\/\",\"name\":\"Number Crunch\",\"description\":\"A computational science blog.\",\"publisher\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.numbercrunch.de\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\",\"name\":\"Heiko Bauke\",\"logo\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++11\/14 for scientific computing II - Number Crunch","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/","og_locale":"en_US","og_type":"article","og_title":"C++11\/14 for scientific computing II - Number Crunch","og_description":"Complex numbers The template class std::complex and functions for complex numbers (defined in the header file complex) have been extended in C++11\/14. The new function std::proj returns the projection of the complex number $z$ onto the Riemann sphere. The functions std::asin, std::acos and std::atan calculate the inverse of the sine, cosine and tangent for complex&hellip; Continue reading C++11\/14 for scientific computing II","og_url":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/","og_site_name":"Number Crunch","article_published_time":"2014-12-19T12:15:07+00:00","article_modified_time":"2023-01-18T21:20:01+00:00","author":"Heiko Bauke","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Heiko Bauke","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#article","isPartOf":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/"},"author":{"name":"Heiko Bauke","@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413"},"headline":"C++11\/14 for scientific computing II","datePublished":"2014-12-19T12:15:07+00:00","dateModified":"2023-01-18T21:20:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/"},"wordCount":153,"commentCount":0,"publisher":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413"},"articleSection":["C++"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/","url":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/","name":"C++11\/14 for scientific computing II - Number Crunch","isPartOf":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#website"},"datePublished":"2014-12-19T12:15:07+00:00","dateModified":"2023-01-18T21:20:01+00:00","breadcrumb":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-ii\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.numbercrunch.de\/blog\/"},{"@type":"ListItem","position":2,"name":"C++11\/14 for scientific computing II"}]},{"@type":"WebSite","@id":"https:\/\/www.numbercrunch.de\/blog\/#website","url":"https:\/\/www.numbercrunch.de\/blog\/","name":"Number Crunch","description":"A computational science blog.","publisher":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.numbercrunch.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413","name":"Heiko Bauke","logo":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/592"}],"collection":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/comments?post=592"}],"version-history":[{"count":8,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/592\/revisions"}],"predecessor-version":[{"id":971,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/592\/revisions\/971"}],"wp:attachment":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/media?parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/categories?post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/tags?post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}