Knowledge Base

W = (float){Ascii2Decimal[(bb+I)..(bb+I+min(fw,nn))]}; I = I+{number of characters consumed}; R = (valid result) ? 0 : 1

Extract (Get) a floating point number from a buffer in RAM.

Consider an Xwire receive data block to be nn bytes of RAM long, starting at address bb. Return a decimal number from the data block, starting at RAM address bb+I (i.e. the starting address is indexed). Skip any leading spaces. Process leading + or – sign, if present. Terminate on anything thereafter that’s not a decimal digit or decimal point, or after processing fw (field width) characters in total (including spaces, sign and decimal point). Advance I past the characters used, leaving it pointing at the terminating character (auto-index). Result in W, NaN if nothing there. R register signals outcome. 0 = OK, 1 = no valid decimal number present.

Notes:

  1. Typically used for receiving ASCII-coded information from an Xwire peripheral board.
  2. The field width fw includes leading spaces, signs and decimal point.
  3. Conversion will end on the first unexpected character, including a second sign character, a second decimal point or a trailing space. This overrides the field width.
  4. The valid range for fw is 1 to 255. fw = 255 disables character counting.
  5. Anything more than 7 digits of input is meaningless, as the floating point number representation is only accurate to 6 or 7 decimal places. Excess digits will be nevertheless be consumed, up to the limits of nn and fw.

Dialect exclusions: Not available in dialects before 28

See also: iifPrintWFWiifPrintWVW,

Examples

The following shows the result of the instruction iifGetNum 100,15,8 for various RAM contents and Values of I.

Data in RAM, starting at address 100 (Shown as ASCII (printable) characters.Initial value of IResult returned in WFinal value of IComment
123.456xxxxxxxx0123.4567Conversion starts at the first character, because I = 0. Conversion is terminated by the first x.
123.456xxxxxxxx123.4567Conversion starts at the second character, because I = 1.
123.456xxxx01238Leading spaces are counted in the field width. The decimal point “makes it”, and I gets left pointing at the 4. A subsequent conversion with the same instruction would return 456
-123.456xxxxxxx0-123.4568All good, got it all
-123.456xxxxxx0-123.458The last digit is excluded, because the field width of 8 terminates conversion. Furthermore, a subsequent conversion would return 6.
-12.3.456xxxxxx0-12.36The second decimal point terminates conversion. If the same instruction were executed again (with I as-is), it would return 0.456