Jspice3
printnum.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1987 Wayne A. Christopher
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /* Print a number in a reasonable form. This is the sort of thing that
9  * %G does, but more appropriate for spice. Returns static data.
10  */
11 
12 #include "spice.h"
13 #include "misc.h"
14 
15 int cp_numdgt = -1;
16 
17 
18 char *
19 fixxp2(str)
20 
21 /* use two digit exponent if possible */
22 char *str;
23 {
24  char *ss;
25  int xp;
26 
27  ss = strchr(str,'e');
28  if (!ss) ss = strchr(str,'E');
29  if (!ss) return (str);
30  ss++;
31  xp = atoi(ss);
32 
33  if (xp > 99) return str;
34  if (xp < -99) return str;
35 
36  if (xp < 0) {
37  *ss = '-';
38  xp = -xp;
39  }
40  else
41  *ss = '+';
42  *(ss+1) = '0' + (xp/10);
43  *(ss+2) = '0' + (xp%10);
44  *(ss+3) = '\0';
45  if (*str == '+')
46  *str = ' ';
47  return (str);
48 }
49 
50 
51 char *
53 
54 /* format: %.ne, with 2 exponent digits
55  * used in agraf.c and printnum()
56  */
57 double d;
58 int n;
59 {
60  static char s[32];
61 
62  sprintf(s,"%+.*e",n,d);
63  return (fixxp2(s));
64 }
65 
66 
67 char *
69 
70 double num;
71 {
72  static char buf[128];
73  int n;
74 
75  if (cp_numdgt > 1)
76  n = cp_numdgt;
77  else
78  n = 6;
79  return (ecvt_n(num,n));
80 }
81 
82 
83 
static char buf[MAXPROMPT]
Definition: arg.c:18
char * fixxp2(char *str)
Definition: printnum.c:19
Definition: cddefs.h:119
char * ecvt_n(double d, int n)
Definition: printnum.c:52
Definition: cddefs.h:237
int cp_numdgt
Definition: printnum.c:15
char * printnum(double num)
Definition: printnum.c:68