Announcement

Collapse
No announcement yet.

floating point vars: Endianess, Saving to media, and validation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ESPsupport
    replied
    It doesn't really matter, as long as you read it back the same way, but [0] first is more 'correct' in some ways

    AFAIK all possible values are valid, they just resolve to difference numbers

    Leave a comment:


  • floating point vars: Endianess, Saving to media, and validation

    What's the best way to save and retrieve a floating point value to/from the SD card?

    The following code reads from the SD card, checks if the value read is in a range. If not, set to the minimum, and write back to the SD Card.

    Code:
    #constant MIN_ISET  "0.0"
    #constant MAX_ISET  "10.0"
    #constant ADD_ISET 0
    
    var flt_Iset[2], flt_Imin[2], flt_Imax[2];
    
    flt_VAL(flt_Imin,MIN_ISET);
    flt_VAL(flt_Imax,MAX_ISET);
    
    if(media_Init())
        media_SetAdd(0,ADD_ISET);
        flt_Iset[0] := media_ReadWord();
        flt_Iset[1] := media_ReadWord();
        if(flt_LT(flt_Iset, flt_Imin) || flt_GT(flt_Iset, flt_Imax))
            flt_VAL(flt_Iset,MIN_ISET);
            media_SetAdd(0,ADD_ISET);
            media_WriteWord(flt_Iset[0]);
            media_WriteWord(flt_Iset[1]);
        endif
    endif
    In what order should the words of a float be read and written? the [0] word first, or the [1] word first?

    And is there a way to test for an invalid float value (+INF, -INF, qNAN, sNAN)?

Working...
X