• AVR Freaks

Hot!behavior of double in debug in MPLab x ver 5.25 & xc32 compiler

Author
MPaulHolmes
Junior Member
  • Total Posts : 79
  • Reward points : 0
  • Joined: 2009/10/31 10:52:40
  • Location: 0
  • Status: offline
2020/02/05 22:08:27 (permalink)
4 (1)

behavior of double in debug in MPLab x ver 5.25 & xc32 compiler

I am using the pic32mk family, which has double precision floating built into the hardware.  I was doing some timing tests with float, and things seem to work fine.  When I try to do some tests with double, the watch window shows the wrong result for double arithmetic.  Here's an example:
 

 
double x = 0.0L, y = 23.123456789L, z = 1234.567891011L;  // I added the "L" since I heard there was a bug with xc compilers.
 
x = y * z;
 

 
When I look at the watch, it seems to only be able to store them as float.  Even if I go to the watch window, and go to change the type to "IEEE double", it still stays as float.  Is it just the watch that's showing the wrong thing, or does the double precision multiply actually not happen?
 
Nevermind.  I just found another thread that mentions that you have to cast "double" as "long double" for it to be 8 byte double.  So, I think double == float, and long double == double.
post edited by MPaulHolmes - 2020/02/05 22:26:17
#1

3 Replies Related Threads

    andersm
    Super Member
    • Total Posts : 2778
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: offline
    Re: behavior of double in debug in MPLab x ver 5.25 & xc32 compiler 2020/02/05 23:47:26 (permalink)
    +2 (2)
    Are you compiling with 32- or 64-bit doubles?
    #2
    MPaulHolmes
    Junior Member
    • Total Posts : 79
    • Reward points : 0
    • Joined: 2009/10/31 10:52:40
    • Location: 0
    • Status: offline
    Re: behavior of double in debug in MPLab x ver 5.25 & xc32 compiler 2020/02/06 05:15:57 (permalink)
    0
    I didn't know that was an option for choices.  Oh!  I found this option:
    -fno-short-double
     
    That may create issues evidently when passing doubles to functions in libraries that have assumed that double is 32 bit, so maybe I shouldn't do that.
    post edited by MPaulHolmes - 2020/02/06 05:34:36
    #3
    JasonK
    Moderator
    • Total Posts : 3404
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    Re: behavior of double in debug in MPLab x ver 5.25 & xc32 compiler 2020/02/25 15:36:51 (permalink)
    +2 (2)
    Starting in MPLAB XC32 v2.40 for PIC32M devices, the 'double' type is now 64-bits wide and the -fshort-double option is deprecated.

    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5