-2

I'm trying to bit shift 63 places to the left. I keep getting an "expression must have an integral or unscoped enum type. I'm fairly new to C++ so I'm sure it's something very simple.

#include <iostream>

using namespace std;
int sign_bit(double x){
    double temp = x << 63; // this is the line that is throwing the error
    int return_value = reinterpret_cast<int>(temp); 
    return return_value; 
}

int main(){
    double n = -1.00;
    double p = 1.00;
    return 0;
}
Appleshell
  • 7,088
  • 6
  • 47
  • 96
user133688
  • 6,864
  • 3
  • 20
  • 36
  • 2
    According to the error, you can only bitshift integer types, try `static_cast(x) << 63` – yizzlez Jan 27 '14 at 22:32
  • 1
    You cannot bit-shift a double, because floating-point values are stored in a form that is different from integral types. Try using a `long long` or an `int64`. Of course, that requires your platform to support 64-bit integers. – Adam Liss Jan 27 '14 at 22:33
  • 2
    @AdamLiss The name of the type is `long long`, not `int64`, and it is required by both the C and the C++ standards (and I don't know of a modern compiler which doesn't support it, since it was required by C since C99). – James Kanze Jan 27 '14 at 22:42

1 Answers1

2

You can't bit shift floating point types. And why exactly would you want to anyway? Try re-doing your code using integer types, or casting to int types, and see here: How to perform a bitwise operation on floating point numbers

Community
  • 1
  • 1
Ozraptor
  • 564
  • 4
  • 11