Skip to content

Adjust an experiment #7

Description

@dmitri-mamrukov

In https://github.com/cpp-tutor/learnmoderncpp-tutorial/blob/main/02-variables-scopes-and-namespaces.md.

"Now change {1} to {1LL}. Does the code still compile? Try to fix this."

I tried and it compiled. I believe that the above sentence should be adjusted.

`#include
using namespace std;

int main() {
int c = {static_cast(2.5)};
// LL is long long int.
// This compiles because the value 1 can be exactly represented as a double.
double d = {1LL};
println("c = {}, d = {}", c, d);

// 2^53 + 1 — not exactly representable.
// 2^53 + 1 exceeds the 53-bit mantissa of double, so it rounds — and that
// rounding is what the brace-init rule forbids.
//
// error: narrowing conversion of ‘9007199254740993’ from ‘long long int’ to
// ‘double’ [-Wnarrowing]
// double e = {9007199254740993LL};
}`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions