S\->N -- Converts SPICE-scaled value string into a real number Version 1.1 1993/10/19 (C) Copyright 1993 by James Unterburger. All rights reserved. 295 bytes #6F2Bh checksum Converts SPICE-scaled value strings into real numbers INPUT: 1: string of SPICE-scaled number, e.g., "-1.234MEG", OR real number (which is just passed through as-is with no processing) OUTPUT: 1: real number representation of value, e.g., -1.234E6 This string-to-real-number converter recognizes the following SPICE scale factors: F = 1E-15 P = 1E-12 N = 1E-09 U = 1E-06 M = 1E-03 K = 1E+03 MEG = 1E+06 (same as 'ME', just like SPICE) G = 1E+09 T = 1E+12 Note that the SPICE2G.6-supported token MIL = 2.54E-02 is NOT SUPPORTED. This routine uses the first 15 significant digits of the manitissa when constructing its output number which is rounded to 12-digits, a standard HP48SX real number. Numbers with more than 15 digits can be used as input, but only the first 15 significant digits will be used (and then rounded to 12 digits). This routine is case-insensitive. Scientific notation is legal and will produce expected results. Only the first 3 digits of the exponent will be used, and they should not exceed the maximum of 499; else an Overflow condition will exist. Exponents less than -499 will the cause corresponding Positive or Negative Underflow condition to exist. Both Overflow and Underflow conditions are handled according to the system flags for Math exceptions; see the user's manual for details about which flags these are. ######## THIS ROUTINE ALWAYS RETURNS A VALUE ######### This routine differs from SPICE in several unimportant ways which relate to the handling of non-standard characters in the input string. This routine will return the value of as much of the input string as can be parsed as a number, returning zero for non-parseable numbers, whereas SPICE will sometimes generate an error for non-parseable numbers. Furthermore, this routine ignores all leading non-numeric characters whose ASCII code less is than or equal to 2Ch, the comma character ","), whereas SPICE will treat leading commas differently. Since leading plus characters ("+") are ignored, numbers with 2 or more leading "+" characters (which cause an error in SPICE?) will parse OK in this routine. Stick to generally recognizable numbers and you will be OK. Mixing scientific notation and SPICE-scale factors has the same affect as in SPICE, i.e., the scale factor is ignored. Examples: "12345.t" ==> 1.2345E16 "1.2345e-034" ==> 1.2345E-34 "-1.234E+0234" ==> -1.234E23 "(,++-.0023x8" ==> -2.3E-3 "-12345678901234567890K" ==> -1.23456789012E22 "-123.4e2K" ==> -1.234E4 " BEAVIS " ==> 0 This routine was tested on a HP48SX-E machine, but since it uses only supported entry points and involves no graphics and other fancy doings, it is anticipated that it will work fine on the HP48G/X series. Finally, I wrote and rewrote this routine trying to minimize the size, so there are certain inefficiencies in the processing as far as speed goes. So don't flame me for these; rather, praise me for how compact and robust the code is! (C) Copyright 1993 by James Unterburger. All rights reserved. Noncommercial distribution allowed, provided that this copyright message is preserved, and any modified versions are clearly marked as such. This routine may not be used in any commercial product without my permission. "Shareware" and "Giftware" are both included in this restriction. This program makes use of undocumented low-level features of the HP48SX calculator, and may or may not cause loss of data, excessive battery drainage, and/or damage to the calculator hardware. The Author takes no responsibility whatsoever for any damage caused by the use of or inability to use this program. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.