Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 943531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:27:07+00:00 2026-05-15T22:27:07+00:00

On my platform this prints 9223372036854775808. double x = 1e19; std::cout << static_cast<unsigned __int64>(x)

  • 0

On my platform this prints 9223372036854775808.

double x = 1e19;
std::cout << static_cast<unsigned __int64>(x) << '\n';

I tried Boost.NumericConversion, but got the same result.

Splitting x into 2 equal part, then adding together converted halves give the correct result. But I need a generic solution to use in a template code.

Thank you in advance.

EDIT:
This problem shows up on Visual Studio 2008, but not MinGW. Casting 4.0e9 into unsigned long works fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:27:07+00:00Added an answer on May 15, 2026 at 10:27 pm

    Seems like it works well with gcc, but it is problematic in Visual Studio. See Microsoft’s answer regarding this issue:

    Our floating-point to integer
    conversions are always done to a
    signed integer. In this particular
    case we use FIST instruction which
    generates 800..00 as you described.
    Therefore, there is no defined
    behavior for converting to unsigned
    64-bit integer values which are
    larger than largest 64-bit signed
    integer.

    So you can only convert the numbers in the signed 64-bit integer range: −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 (-2^63~2^63-1).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I think this question is platform independent, but I happen to be coding for
On all others versions of platform I use this: BrowserFieldConfig cfg = new BrowserFieldConfig();
This isn't cross-platform code... everything is being performed on the same platform (i.e. endianess
MY Table like this: id Tag platform 1 #class1,#class2 CS 2 #class1 PS 3
I'd like to do this in a platform independant way, and I know libpng
I am reading this book Beginning Java™ EE 6 Platform with GlassFish™ 3: From
This is in Java, cross platform and being debugged on a computer running Ubuntu
I use Codeigniter platform to make a website I used this .load script to
I just finished looking at this question: https://stackoverflow.com/questions/753122/which-cloud-computing-platform-should-i-choose But, I am not certain what
I heard this term recently. What are subscription applications(for a mobile platform). Does this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.