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 8828507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:37:17+00:00 2026-06-14T07:37:17+00:00

I have to multiply an integer value by 2^31. I have googled it, and

  • 0

I have to multiply an integer value by 2^31. I have googled it, and it looks like doubles have a range among 2.23e-308 <= |X| <= 1.79e308 when using 64 bits, and a float among 1.18e-38 <= |X| <= 3.40e38.

That’s a lot more than what I need. But it doesn’t work.

I have this constant value in my header file:

static const float SCALE_FACTOR = 2^-31;

and if then I just do:

float dummy = SCALE_FACTOR;

Then, dummy’s value is 11.

I don’t know if the problem is assigning a constant value like that, but I don’t know how else to write it without losing precision.

Any help?

EDIT:Sorry, stupid question. My MatLab background betrayed me and forgot that ^ is not for exponentiation in C++. I have voted to close.

  • 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-06-14T07:37:19+00:00Added an answer on June 14, 2026 at 7:37 am

    ^ is a bitwise xor operator in C++, not a mathematical exponentiation operator. You have a few alternatives.

    1. Because you’re storing the constant in an intrinsically lossy format, a float, you could just work out the base-10 e form literal and use that: perhaps something like 4.6566128730773926e-010 for 2^-31. This is prone to error (I’ve made one, for example), and isn’t necessarily portable between floating point formats.
    2. You can set the constant using a constant expression that can be evaluated at compile time, and use an integer literal: either 0x80000000 or 1UL << 31 for 2^31, or 1.0f / 0x80000000 for 2^-31 for example.

    You could use a pow function of some kind to calculate the value at runtime, of course.

    Incidentally, if you’re using integers, why not just use a long long or other 64bit integral type, instead of a floating point which may well present you with rounding errors? It isn’t totally clear from your question whether you are looking at floating point values because you need floating point value ranges, or because you are merely worried about overflowing a 32-bit integer value.

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

Sidebar

Related Questions

I have to load an array of doubles from a file, multiply each element
I have a method which just increases an Integer Value (i++) public void Calculate()
I have a table with four columns, say P_Key(int), Ref_Key(int), Key(String), Value(Integer). I want
In my C++ code I have an expression where I multiply unsigned long integer
I have a multiply nested namespace: namespace first {namespace second {namespace third { //
I have to multiply a very small sized matrix ( size - 10x10 )
I have 2 matrices and I need to multiply them and then print the
I have two fields that need to multiply each other and fill a third
I have a vector class and I defined the __mul__ method to multiply a
I have 1 million rows in MySql table temp and wish to multiply column

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.