dword to float changes, lost of accuracy


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member amateurtje's Avatar
    Join Date
    Aug 2008
    Posts
    116
    Thumbs Up
    Received: 3
    Given: 2
    Total Downloaded
    98.25 MB

    0 Not allowed!

    Default dword to float changes, lost of accuracy

    Hello,

    I need to change a Dword into a float with a lot of decimals behind the comma. Already, when making the dword into the float (before the devision to make it a decimal number) it goes wrong.

    The dword: dwordnumber =51456487
    Floatnumber = dwordnumber gives 51456254.72

    Of course, I need it to be 51456487 and later with a division I need to make it :
    Floatnumber = floatnumber / 1000000

    Here the Floatnumber becomes: 51.45626008
    (I need it to be: 51.456487!!!

    How can I make this floatnumber of thisdwordnumber?

    I have tried:
    Declare Float_Rounding = On
    Declare Float_Display_Type = LARGE '(And Fast)

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,779
    Thumbs Up
    Received: 83
    Given: 34
    Total Downloaded
    4.30 GB

    0 Not allowed!

    Default Re: dword to float changes, lost of accuracy

    Greetings,
    You've come up against the accuracy limit of 4 byte float variables. You may be able to overcome your problem by making use of Integer division (div) and mod.
    There is an article on this in the WIKI in the maths section.
    John

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,215
    Thumbs Up
    Received: 74
    Given: 180
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: dword to float changes, lost of accuracy

    As John says, it's the nature of the beast. Any compiler that uses Microchip floating point format (which I suspect is all of them) has the same problem.
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    485
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    330.54 MB

    0 Not allowed!

    Default Re: dword to float changes, lost of accuracy

    not trying to nit-pick, but
    Any compiler that uses ANY 32-bit floating point format...
    32-bits gets you roughly 6-7 decimal digits of precision. Doesn't matter (much) if the digits are before or after the decimal point, it's 6-7 digits total.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,779
    Thumbs Up
    Received: 83
    Given: 34
    Total Downloaded
    4.30 GB

    0 Not allowed!

    Default Re: dword to float changes, lost of accuracy

    Amateurtje,
    If you need greater precision use a 16 bit chip (e.g pic24fxxx) as the compiler supports 64 bit (8byte) floats in these and a significant improvement in accuracy.
    Just as an example as a follow up to Tumbleweed floats in day to day computer programs are rarely accurate.
    In the programming language Delphi a person can use 128bit floats in an attempt to be more accurate when representing floating point numbers.
    By the way using the float_display_type directive doesn't change the underlying value of the float, all it does is have a better shot at displaying the number.
    John
    Last edited by John Drew; 1st November 2019 at 23:18. Reason: My phone changes words all by itself!

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Float To Dword Assignment
      By SELCUK in forum Proton Plus Compiler v3
      Replies: 5
      Last Post: 1st February 2009, 11:45
    2. NE555 Accuracy?
      By Darlington in forum The Lounge
      Replies: 12
      Last Post: 15th January 2009, 12:28
    3. Accuracy of Float calculations
      By John Drew in forum Wish List / Product Feedback
      Replies: 33
      Last Post: 7th January 2007, 15:20
    4. dword and float variables in interrupt
      By aatschouten in forum Proton Plus Compiler v3
      Replies: 10
      Last Post: 13th March 2006, 11:22

    Members who have read this thread : 31

    Actions :  (Set Date)

    You do not have permission to view the list of names.

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts