Floating point anomaly?


+ Reply to Thread
Results 1 to 4 of 4

Thread: Floating point anomaly?1282 days old

  1. #1
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    557
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Floating point anomaly?

    Unless I'm misunderstanding something, which is always possible, I think I've found an anomaly with Proton's floating point routine.


    From page 51 of the manual...

    Float type variables may theoretically hold a value from -1e37 to +1e38, but because of
    the 32-bit architecture of the compiler, a maximum and minimum value should be
    thought of as -2147483646.999 to +2147483646.999 making this the most versatile of
    the variable family types.
    However, I'm finding that numbers greater than 8388607 (2^23 -1) change to zero. This makes me wonder if there is something amiss with that part of the floating point routine which deals with the number exponent.

    Before reporting this formally as an anomaly, could someone try out this code and see if they obtain the same results as myself? That is numbers greater than 8388607 become 0. Also, if I'm doing something stupid, please let me know!

    Code:
      Device = 18F25K22
      Xtal = 64
    
      Declare All_Digital = true
    
     'Calculated Baudrate = 115108 @ Xtal 64MHz, Error = -0.08%
      Declare Hserial_RCSTA  = 144 ; Enable continuous receive
      Declare Hserial_TXSTA  = 36  ; Enable transmit, BRGH = 1
      Declare Hserial_Clear  = On  ; Clear overflow automatically
      Declare Hserial_SPBRG  = 138 ; Baud Rate Generator Low Byte Value
      SPBRGH                 = 0   ; Baud Rate Generator High Byte Value
      BAUDCON.3              = 1   ; Enable the 16 bit Baud Rate Generator
    ;-------------------------------------------------------------------------------
    
    
    Dim TestVar1 As Float = 8388600.0
    Dim TestVar2 As Float = 0
    
    
    Main: 
        HSerOut ["TestVar1 = ",Dec3 TestVar1,13,10]
        TestVar2 = TestVar1/100
        HSerOut ["TestVar2 = ",Dec3 TestVar1,13,10,13,10]   
        TestVar1 = TestVar1 + 1
        DelayMS 1000
        GoTo Main
    End  
    
    ' **** Added by Fuse Configurator ****
    ' Use the Fuse Configurator plug-in to change these settings
    
    
      Config_Start
          FOSC = HSMP    ;HS oscillator (medium power 4-16 MHz)
          PLLCFG = On    ;Oscillator multiplied by 4
          PRICLKEN = On    ;Primary clock enabled
          FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
          IESO = OFF    ;Oscillator Switchover mode disabled
          PWRTEN = OFF    ;Power up timer disabled
          BOREN = SBORDIS    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
          BORV = 190    ;VBOR set to 1.90 V nominal
          WDTEN = Off    ;WDT is always enabled. SWDTEN bit has no effect
          WDTPS = 32768    ;1:32768
          CCP2MX = PORTC1    ;CCP2 input/output is multiplexed with RC1
          PBADEN = On    ;PORTB<5:0> pins are configured as analog input channels on Reset
          CCP3MX = PORTB5    ;P3A/CCP3 input/output is multiplexed with RB5
          HFOFST = On    ;HFINTOSC output and ready status are not delayed by the oscillator stable status
          T3CMX = PORTC0    ;T3CKI is on RC0
          P2BMX = PORTB5    ;P2B is on RB5
          MCLRE = EXTMCLR    ;MCLR pin enabled, RE3 input pin disabled
          STVREN = On    ;Stack full/underflow will cause Reset
          LVP = On    ;Single-Supply ICSP enabled if MCLRE is also 1
          XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
          Debug = OFF    ;Disabled
          Cp0 = OFF    ;Block 0 (000800-001FFFh) not code-protected
          CP1 = OFF    ;Block 1 (002000-003FFFh) not code-protected
          CP2 = OFF    ;Block 2 (004000-005FFFh) not code-protected
          CP3 = OFF    ;Block 3 (006000-007FFFh) not code-protected
          CPB = OFF    ;Boot block (000000-0007FFh) not code-protected
          CPD = OFF    ;Data EEPROM not code-protected
          WRT0 = OFF    ;Block 0 (000800-001FFFh) not write-protected
          WRT1 = OFF    ;Block 1 (002000-003FFFh) not write-protected
          WRT2 = OFF    ;Block 2 (004000-005FFFh) not write-protected
          WRT3 = OFF    ;Block 3 (006000-007FFFh) not write-protected
          WRTC = OFF    ;Configuration registers (300000-3000FFh) not write-protected
          WRTB = OFF    ;Boot Block (000000-0007FFh) not write-protected
          WRTD = OFF    ;Data EEPROM not write-protected
          EBTR0 = OFF    ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
          EBTR1 = OFF    ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
          EBTR2 = OFF    ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
          EBTR3 = OFF    ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
          EBTRB = OFF    ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
      Config_End
    
    ;**** End of Fuse Configurator Settings ****
    ;----------------------------------
    I'm using Proton 3.5.8.4 on Windows 10.

    Thanks,

    Bob
    Last edited by Mellbreak; 3rd June 2016 at 12:57.

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
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    487
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    330.54 MB

    1 Not allowed!

    Default Re: Floating point anomaly?

    I ran it in a debugger and the actual floating-point calculations are working ok.

    The issue you're seeing seems to be with the hserout/DEC3 formatting.

  • 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
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    557
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Re: Floating point anomaly?

    Thanks Tumbleweed for taking the time to look at this problem. If I hadn't made a silly mistake in my program, I'd have realised this.

    The line ....

    HSerOut ["TestVar2 = ",Dec3 TestVar1,13,10,13,10]

    Should read ....

    HSerOut ["TestVar2 = ",Dec3 TestVar2,13,10,13,10]

    The idea was by dividing by TestVar1 by 100 I could bring the number back into the displayable range and confirm it was still incrementing.

    I'll have a further play before reporting the anomaly.

    Thanks again.

    Bob

  • 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 Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    557
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Re: Floating point anomaly?

    A work around for this problem is to use....

    Declare Float_Display_Type = Fast


    With this declare in place all works as expected.

    Bob

  • 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. Floating point question
      By charliecoultas in forum The Lounge
      Replies: 11
      Last Post: 30th August 2017, 11:18
    2. Floating point anomaly?
      By joesaliba in forum Proton Plus Compiler v3
      Replies: 6
      Last Post: 20th January 2015, 23:27
    3. [SOLVED !] Floating point to Byte?
      By Russ_Meyer in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 28th August 2009, 20:55
    4. Floating point numbers
      By John Drew in forum Proton Plus Compiler v3
      Replies: 4
      Last Post: 29th March 2009, 00:09
    5. Floating point errors
      By Dave-S in forum Proton Plus Compiler v3
      Replies: 6
      Last Post: 4th June 2007, 21:20

    Members who have read this thread since 29th October 2019, 10:48 : 0

    Actions :  (Set Date)  (Clear Date)

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

    Tags for this Thread

    Posting Permissions

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