Typing in binary numbers with decimal point

Issue #445 closed
Former user created an issue

Originally reported on Google Code with ID 445

Typing in the decimal value 1,15625 and showing the binary result gives:
0b1.00101

But there is no way you can type in a binary number with decimal point e.g. 0b10.01
(which should be equal to 2.25).

Can this be fixed?

Reported by kent.kinna on 2013-08-20 13:34:58

Comments (10)

  1. Former user Account Deleted
    Hi, Kent. I'm curious to know what your use case is that requires input of non-integer
    binary numbers.
    

    Reported by helder.pereira.correia on 2014-02-18 01:17:01

  2. Former user Account Deleted
    Hello, thanks for looking into this.
    
    When representing a number with decimals in hardware (e.g. FPGA), the
    decimal point could be set at any digit.
    E.g.
    A binary number:
    101001 with 2 decimal bits will be 1010.01 (bin) = 10.25 (dec)
    When verifying DSP functionality there might be a model that calculates in
    real numbers e.g. MATLAB. Comparing the results between MATLAB and HW
    (simulated or measured) might (or will at some ponit) end up in comparing a
    MATLAB model with the HW.
    
    I love the speedcrunch feature with fast conversion between different
    bases, and conversion between a decimal value to a binary works like a
    charm but not the other way around. I can't type in 0b1.1 to get the
    decimal value 1,5.
    
    I hope you understand why I found this functionality useful, please respond
    of there are any more questions.
    

    Reported by kent.kinna on 2014-02-20 06:23:09

  3. Former user Account Deleted
    Indeed, being able to play with non-integer numbers in binary-ish bases is useful when
    designing fixed-point systems.
    
    Is there a specific reason for this feature not being supported since the earliest
    versions of SpeedCrunch ? Maybe I missed something, but the numbers parser in floatio.c
    seems to support numbers with decimal points for every radix, and adding this support
    to Evaluator::scan() seems to be enough to support the whole feature. I did a quick
    and dirty implementation, and it seems to work properly so far.
    

    Reported by teyut@free.fr on 2014-05-01 17:25:38

  4. Former user Account Deleted
    Good feedback!
    Sounds great if there is a quite quick fix for this.
    //
    Kent
    

    Reported by kent.kinna on 2014-05-02 05:20:01

  5. Former user Account Deleted
    @Tey: I don't think there's any reason besides available time and priorities. If you
    have a patch, please post it for review as usual :)
    

    Reported by helder.pereira.correia on 2014-05-05 16:50:37

  6. Former user Account Deleted
    Okay, here's a patch:
    https://github.com/Tey/SpeedCrunch/commit/69dd5abd0eea0e05fcadc4f794134477a1e10fbc
    
    I also tried adding support for exponents, but the number parser in the math lib does
    not support that (though it can display such numbers).
    

    Reported by teyut@free.fr on 2014-05-06 15:00:03

  7. Former user Account Deleted
    A more compact implementation (but which uses a state variable):
    https://github.com/Tey/SpeedCrunch/commit/4ca56ea2ca46b98f6303c49c90841189f4c4841e
    
    I forgot to remove the new parsing states from this commit though. Choose the one you
    prefer :)
    

    Reported by teyut@free.fr on 2014-05-06 15:14:38

  8. Former user Account Deleted
    Thanks, Tey. Added in revision 30a3ff3. I added another change for tests.
    

    Reported by helder.pereira.correia on 2014-05-08 07:19:12 - Status changed: Fixed - Labels added: Type-Enhancement, Milestone-0.12

  9. Log in to comment