Alex028502
Alex028502

Reputation: 3814

fractions in binary and hex

Is there any language that can handle non decimal floating point numbers the same way they can with integers. The following happens in python, javascript, elixir...

>>> 0b11
3
>>> 0b11 + 0b11
6
>>> 0b1.1
Some kind of Syntax Error
>>> 0b1.1 + 0b1.1
Some kind of Syntax Error

I want to see

>>> 0b1.1
1.5
>>> 0b1.1 + 0b1.1
3

(This might break the recommend a tool rule, but I don't see how it could especially attract opinionated answers so going for it; might delete it if people are offended)

Upvotes: 0

Views: 71

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 223389

C has hexadecimal floating-point constants in the form 0x hexadecimal-digits . hexadecimal-digits p signoptional decimal-digits, where the digits before or after the . are optional, but one must be present. For example, 0x7.afp4. The p and decimal-digits specify a power of two, which the hexadecimal portion is multiplied by.

Upvotes: 2

Related Questions