home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / mac / programm / 18314 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.5 KB  |  65 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!mcsun!inesc.inesc.pt!mujave!mms
  3. From: mms@mujave.inesc.pt (Miguel Mira da Silva)
  4. Subject: econvert(), fconvert()
  5. Message-ID: <1992Nov12.110609.2229@inesc.pt>
  6. Sender: mms@mujave (Miguel Mira da Silva)
  7. Nntp-Posting-Host: mujave.inesc.pt
  8. Organization: INESC - Inst. Eng. Sistemas e Computadores, LISBOA. PORTUGAL.
  9. Date: Thu, 12 Nov 1992 11:06:09 GMT
  10. Lines: 53
  11.  
  12. I am trying to port some UNIX software to the MAC under Think C 4.0, but there are
  13. two functions I could not find in any library that comes with Think C. They are:
  14.  
  15.      char *econvert(value, ndigit, decpt, sign, buf)
  16.      double value;
  17.      int ndigit, *decpt, *sign;
  18.      char *buf;
  19.  
  20.      char *fconvert(value, ndigit, decpt, sign, buf)
  21.      double value;
  22.      int ndigit, *decpt, *sign;
  23.      char *buf;
  24.  
  25. The description on my SUN is:
  26.  
  27.      econvert() converts the value to a null-terminated string of
  28.      ndigit  ASCII  digits  in  buf and returns a pointer to buf.
  29.      buf should contain at least ndigit+1 characters.  The  posi-
  30.      tion of the radix character relative to the beginning of the
  31.      string is stored indirectly  through  decpt.   Thus  buf  ==
  32.      "314"  and  *decpt  ==  1 corresponds to the numerical value
  33.      3.14, while buf == "314" and *decpt == -1 corresponds to the
  34.      numerical  value  .0314.  If the sign of the result is nega-
  35.      tive, the word pointed to by sign is nonzero;  otherwise  it
  36.      is zero.  The least significant digit is rounded.
  37.  
  38.      fconvert works much like econvert, except that  the  correct
  39.      digit  has been rounded as if for sprintf(%w.nf) output with
  40.      n=ndigit digits to the right of the radix character.  ndigit
  41.      can  be  negative  to  indicate  rounding to the left of the
  42.      radix character.  The return value is a pointer to buf.  buf
  43.      should  contain  at  least  310+max(0,ndigit)  characters to
  44.      accomodate any double-precision value.
  45.  
  46. Also,
  47.  
  48.      ecvt() and fcvt() are obsolete versions  of  econvert()  and
  49.      fconvert()  that  create  a  string  in  a static data area,
  50.      overwritten by each call, and return values  that  point  to
  51.      that  static  data.  These functions are therefore not reen-
  52.      trant.
  53.  
  54. I tried already to implement them for myself, but it is not quite obvious.
  55. I was wondering if anybody has had the same problem, or if the solution
  56. comes on any book of "C utilities". Any help is appreciated.
  57.  
  58. Thanks in advance,
  59.  
  60. Miguel.
  61.  
  62. ---
  63. Miguel Mira da Silva
  64. mms@mujave.inesc.pt
  65.