Double (IEEE754 Double precision 64-bit)

ArFe
2012-02-08
2012-02-24
  • ArFe - 2012-02-08

    Hello all,

    I need to use Double instead of Float in Codesys 2.3.
    As I tested, CoDeSys uses float standard for REAL and LREAL. The difference is that the mantissa in LREAL is bigger, but not the exponent, as it should be in Double.
    Bellow you find examples of what it should be.
    http://www.binaryconvert.com/result_dou ... 0048048048
    http://www.binaryconvert.com/result_flo ... 0048048048

    The problem is I need to send the data over a serial connection, and thus, the reception device accepts only Double.
    Is there a library where I can convert LREAL in Double?
    Or does anybody know a function to do so?

    Is it a CoDeSys bug, or it should work like this?

    Thanks in advance,
    Ariel

     
  • shooter - 2012-02-09

    few ways to solve this.
    make your output a string and add some characters needed.
    look w www.oscat.de w and find REAL2
    make yourself a datatype in codesys

     
  • ArFe - 2012-02-09

    Thanks for you reply shooter, but that was not exactly what I need.
    Imagine the scenario I have a display that only accepts double precision numbers (IEEE754), via serial comm, to display.
    If I send REAL or even REAL2 from oscat, I won't have the same byte configuration and I'll display a completely wrong number.
    Because REAL is float
    1 bit sign
    8 bits exponent
    23 bits mantissa
    REAL2 is something based on REAL, so same config, and what I need is
    1 bit sign
    11 bits exponent
    52 bits mantissa

    I've done a brute force conversion, not really sure it will work always.

    Ariel

     
  • shooter - 2012-02-10

    If needed more help, then contact me or put it in oscat forum.
    I can make conversion, however it will need some calcs.
    how did you make it now?

     
  • shooter - 2012-02-11

    It looks working good.
    If you need to do calcs on your doublereal just give a shout.
    btw i saw some differences between the digital one and the binary so be aware of your numbers.

     
  • ArFe - 2012-02-13

    Hi shooter, thanks for your reply and for testing the functions.
    What do you mean by >Zitat:
    differences between the digital one and the binary

    I didn't get it.

     
  • shooter - 2012-02-13

    sorry i meant the decimal and binary one.
    I am working on function block real calculation with very high precision and any number system, so from 2 (being 0..1) to 16 (0..F) including 10 (0..9).
    to have calcs like plus/minus/div/mul.

     
  • ArFe - 2012-02-14

    Yes, the difference is because it's single precision, so it's not that good.
    Cool the project you're working on.

    Cheers,
    Ariel

     
  • jacob6580 - 2012-02-24

    Imagine the scenario I have a display that only accepts double precision numbers (IEEE754), via serial comm, to display.
    If I send REAL or even REAL2 from oscat, I won't have the same byte configuration and I'll display a completely wrong number.
    Because REAL is float
    1 bit sign
    8 bits exponent
    23 bits mantissa


    Escort Bayan

     

Log in to post a comment.