Bitwise Operations on double, float

S

siryuhan

I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.
 
O

osmium

I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?

Note that your first and second paragraph do not agree, the second on talks
only of doubles. There is an IEEE spec on doubles (and, I think, float)
which is reputedly used quite a bit. If you consider that as "portable" you
could restrict yourself to that and maybe get away with calling it portable.

I can't for the life of me imagine why anyone would want to do this. But I
refuse to ask you, it is none of my business and has no bearing on the
answer to the question.
 
J

James Kanze

Note that your first and second paragraph do not agree, the second on talks
only of doubles. There is an IEEE spec on doubles (and, I think, float)
which is reputedly used quite a bit. If you consider that as "portable" you
could restrict yourself to that and maybe get away with calling it portable.
I can't for the life of me imagine why anyone would want to do this. But I
refuse to ask you, it is none of my business and has no bearing on the
answer to the question.

Well, it does, sort of. Because until we know what the
semantics of the operations are supposed to be, it's hard to say
how to best achieve them. What should the result of 1.33 |
3.1419 be? I can't think of anything reasonable.
 
P

peter koch

I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.

No. Even if you can assume e.g. a IEEE float/double, using bit-magic
will not be portable as the representation might differ (similarly to
how unsigned ints have different endianness on different compters).

/Peter
 
N

Nindi

I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.

I am not sure about the meaning of ANDm OR and XOR for doubles, but <<
can be interpreted as multiplication by 2.0 , similarly >> 2 can be
interpreted as multiplication by 0.5. This was the opertations are
consistent with the operatrion for integers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top