{"id":583,"date":"2014-12-17T22:37:05","date_gmt":"2014-12-17T21:37:05","guid":{"rendered":"http:\/\/numbercrunch.de\/blog\/?p=583"},"modified":"2023-01-18T22:21:50","modified_gmt":"2023-01-18T21:21:50","slug":"c1114-for-scientific-computing-i","status":"publish","type":"post","link":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/","title":{"rendered":"C++11\/14 for scientific computing I"},"content":{"rendered":"<p style=\"text-align: justify;\">In 2011, a new standard for the C++ programming language has been published, which is commonly referred to as C++11. This new standard introduces many new language features and standard library functions. Many of these new features have been introduced to make C++ more flexible and to make C++ more easy to use.\u00a0 Bjarne Stroustrup (the creator of C++) even thinks \u00ab<a href=\"www.stroustrup.com\/C++11FAQ.html#think\" target=\"_blank\" rel=\"noopener\">C++11 feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever<\/a>.\u00bb This year another new version of C++ (C++14) has been defined, which brings some minor enhancements and clarifications compared to C++11. As C++ is a general purpose programing language the new features of the revised versions are not specifically designed for the needs of scientific computing. Nevertheless, C++11\/14 adds several new tools to the computational scientist&#8217;s toolbox. In the following I will present some of them.<\/p>\n<h2 style=\"text-align: justify;\">New integer types<\/h2>\n<p style=\"text-align: justify;\">C++ does not define which are the minimal and maximal values that the integer types <code>int<\/code> and <code>long<\/code> can hold. The language standard requires only lower\/upper bounds on these values. As a consequence <code>int<\/code> may be a 16-bit, 32-bit or a 64-bit integer or even something different. In C++11\/14 the standard header file <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/types\/integer\" target=\"_blank\" rel=\"noopener\"><code>cstdint<\/code><\/a> defines several new integer types with specific bit-width.<\/p>\n<table style=\"width: 100%; height: 650px;\">\n<tbody>\n<tr style=\"height: 93px;\">\n<td style=\"height: 93px;\"><code>int8_t<\/code><br \/>\n<code>int16_t<\/code><br \/>\n<code>int32_t<\/code><br \/>\n<code>int64_t<\/code><\/td>\n<td style=\"height: 93px;\">signed integer type with width of<br \/>\n<strong>exactly<\/strong> 8, 16, 32 and 64 bits respectively<br \/>\nwith no padding bits and using 2&#8217;s complement for negative values<br \/>\n(provided only if the implementation directly supports the type)<\/td>\n<\/tr>\n<tr style=\"height: 93px;\">\n<td style=\"height: 93px;\"><code>int_fast8_t<\/code><br \/>\n<code>int_fast16_t<\/code><br \/>\n<code>int_fast32_t<\/code><br \/>\n<code>int_fast64_t<\/code><\/td>\n<td style=\"height: 93px;\">fastest signed integer type with width of<br \/>\n<strong>at least<\/strong> 8, 16, 32 and 64 bits respectively<\/td>\n<\/tr>\n<tr style=\"height: 93px;\">\n<td style=\"height: 93px;\"><code>int_least8_t<\/code><br \/>\n<code>int_least16_t<\/code><br \/>\n<code>int_least32_t<\/code><br \/>\n<code>int_least64_t<\/code><\/td>\n<td style=\"height: 93px;\">smallest signed integer type with width of<br \/>\n<strong>at least<\/strong> 8, 16, 32 and 64 bits respectively<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"height: 23px;\"><code>intmax_t<\/code><\/td>\n<td style=\"height: 23px;\">maximum width integer type<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"height: 23px;\"><code>intptr_t<\/code><\/td>\n<td style=\"height: 23px;\">integer type capable of holding a pointer<\/td>\n<\/tr>\n<tr style=\"height: 93px;\">\n<td style=\"height: 93px;\"><code>uint8_t<\/code><br \/>\n<code>uint16_t<\/code><br \/>\n<code>uint32_t<\/code><br \/>\n<code>uint64_t<\/code><\/td>\n<td style=\"height: 93px;\">unsigned integer type with width of<br \/>\n<strong>exactly<\/strong> 8, 16, 32 and 64 bits respectively<br \/>\n(provided only if the implementation directly supports the type)<\/td>\n<\/tr>\n<tr style=\"height: 93px;\">\n<td style=\"height: 93px;\"><code>uint_fast8_t<\/code><br \/>\n<code>uint_fast16_t<\/code><br \/>\n<code>uint_fast32_t<\/code><br \/>\n<code>uint_fast64_t<\/code><\/td>\n<td style=\"height: 93px;\">fastest unsigned integer type with width of<br \/>\n<strong>at least<\/strong> 8, 16, 32 and 64 bits respectively<\/td>\n<\/tr>\n<tr style=\"height: 93px;\">\n<td style=\"height: 93px;\"><code>uint_least8_t<\/code><br \/>\n<code>uint_least16_t<\/code><br \/>\n<code>uint_least32_t<\/code><br \/>\n<code>uint_least64_t<\/code><\/td>\n<td style=\"height: 93px;\">smallest unsigned integer type with width of<br \/>\n<strong>at least<\/strong> 8, 16, 32 and 64 bits respectively<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"height: 23px;\"><code>uintmax_t<\/code><\/td>\n<td style=\"height: 23px;\">maximum width unsigned integer type<\/td>\n<\/tr>\n<tr class=\"t-dsc\" style=\"height: 23px;\">\n<td style=\"height: 23px;\"><code>uintptr_t<\/code><\/td>\n<td style=\"height: 23px;\">unsigned integer type capable of holding a pointer<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: justify;\">The header file <code>cstdint<\/code> defines also several macros for the maximal and minimal values of the integer types shown above. These values, however, are more conveniently accessed through the template class <code>std::numeric_limits<\/code>.<\/p>\n<h2>Numeric limits<\/h2>\n<p style=\"text-align: justify;\">The class template <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/types\/numeric_limits\" target=\"_blank\" rel=\"noopener\"><code>std::numeric_limits<\/code><\/a>, which is defined in the header file <code>limits<\/code> provides a standardized way to query various properties of arithmetic types (e.g., the largest possible value for type <code>int<\/code> is <code>std::numeric_limits&lt;int&gt;::max<\/code>). This information is provided via specializations of the <code>numeric_limits<\/code> template. Since C++1 the members of <code>std::numeric_limits<\/code> are declared as <code>static <\/code><a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/constexpr\" target=\"_blank\" rel=\"noopener\"><code>constexpr<\/code><\/a>. Thus, their return values can be consumed by operations that require constant expressions, such as an integer template argument. Furthermore, the new members <code>max_digits10<\/code> and <code>lowest<\/code> have been introduced in C++11, which give the number of decimal digits necessary to differentiate all values of this type and the lowest finite value of the given type.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In 2011, a new standard for the C++ programming language has been published, which is commonly referred to as C++11. This new standard introduces many new language features and standard library functions. Many of these new features have been introduced to make C++ more flexible and to make C++ more easy to use.\u00a0 Bjarne Stroustrup&hellip; <a href=\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">C++11\/14 for scientific computing I<\/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-583","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 I - 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-i\/\" \/>\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 I - Number Crunch\" \/>\n<meta property=\"og:description\" content=\"In 2011, a new standard for the C++ programming language has been published, which is commonly referred to as C++11. This new standard introduces many new language features and standard library functions. Many of these new features have been introduced to make C++ more flexible and to make C++ more easy to use.\u00a0 Bjarne Stroustrup&hellip; Continue reading C++11\/14 for scientific computing I\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/\" \/>\n<meta property=\"og:site_name\" content=\"Number Crunch\" \/>\n<meta property=\"article:published_time\" content=\"2014-12-17T21:37:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-18T21:21:50+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=\"3 minutes\" \/>\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-i\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/\"},\"author\":{\"name\":\"Heiko Bauke\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\"},\"headline\":\"C++11\/14 for scientific computing I\",\"datePublished\":\"2014-12-17T21:37:05+00:00\",\"dateModified\":\"2023-01-18T21:21:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/\"},\"wordCount\":480,\"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-i\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/\",\"url\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/\",\"name\":\"C++11\/14 for scientific computing I - Number Crunch\",\"isPartOf\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#website\"},\"datePublished\":\"2014-12-17T21:37:05+00:00\",\"dateModified\":\"2023-01-18T21:21:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/#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 I\"}]},{\"@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 I - 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-i\/","og_locale":"en_US","og_type":"article","og_title":"C++11\/14 for scientific computing I - Number Crunch","og_description":"In 2011, a new standard for the C++ programming language has been published, which is commonly referred to as C++11. This new standard introduces many new language features and standard library functions. Many of these new features have been introduced to make C++ more flexible and to make C++ more easy to use.\u00a0 Bjarne Stroustrup&hellip; Continue reading C++11\/14 for scientific computing I","og_url":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/","og_site_name":"Number Crunch","article_published_time":"2014-12-17T21:37:05+00:00","article_modified_time":"2023-01-18T21:21:50+00:00","author":"Heiko Bauke","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Heiko Bauke","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/#article","isPartOf":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/"},"author":{"name":"Heiko Bauke","@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413"},"headline":"C++11\/14 for scientific computing I","datePublished":"2014-12-17T21:37:05+00:00","dateModified":"2023-01-18T21:21:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/"},"wordCount":480,"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-i\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/","url":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/","name":"C++11\/14 for scientific computing I - Number Crunch","isPartOf":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#website"},"datePublished":"2014-12-17T21:37:05+00:00","dateModified":"2023-01-18T21:21:50+00:00","breadcrumb":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.numbercrunch.de\/blog\/2014\/12\/c1114-for-scientific-computing-i\/#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 I"}]},{"@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\/583"}],"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=583"}],"version-history":[{"count":9,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":973,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions\/973"}],"wp:attachment":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}