0

i want to make a new float type with a size of 128-bit , the exponent would have 4-bytes(32-bit) and the fraction would have 12-bytes(96-bit), how i can make this type in c++, where i will be able to do input, output ,+,-,*,/ operations.

[I am thinking of c++ class but i can't figure how i will mange up between exponent and fraction with the specified length]

I have tried "bitset" std class, but it has a huge size in comparison with what i need for example "std::bitset<16> foo;" give a size of 8-bytes.

Any Suggestions !

Shafik Yaghmour
  • 143,425
  • 33
  • 399
  • 682
Yazan Houshieh
  • 103
  • 1
  • 11

1 Answers1

1

You have to build your own data type and implement all the operations you want to do with it. This is exactly how a compiler emulates a 64 bit dataset when the architecture supports only 32 bit data native.

So a class/struct with two members is the right starting point. You have to implement the basic operations now: +,-,*,/. Add and sub are easy, you need to pay more attention to * and /. What I can tell you is that usually compiles implement these using repeated add and sub operations.

Pandrei
  • 4,683
  • 3
  • 22
  • 42