1 /************************************************************************
3 * Code is modified from the code for Gnuplot by Zou Maorong
6 * G N U P L O T -- standard.c
7 * Copyright (C) 1986, 1987 Thomas Williams, Colin Kelley
8 * You may use this code as you wish if credit is given and this message
11 /****************************************************************************/
17 extern BOOLEAN undefined
;
19 extern struct value stack
[STACK_DEPTH
];
22 struct value
*pop(), *complex(), *integer();
23 double magnitude(), angle(), real(), imag();
27 /***************************************************************************/
32 push( complex(&a
,real(pop(&a
)), 0.0) );
38 push( complex(&a
,imag(pop(&a
)), 0.0) );
44 push( complex(&a
,angle(pop(&a
)), 0.0) );
51 push( complex(&a
,real(&a
),-imag(&a
) ));
58 push( complex(&a
,sin(real(&a
))*cosh(imag(&a
)), cos(real(&a
))*sinh(imag(&a
))) );
65 push( complex(&a
,cos(real(&a
))*cosh(imag(&a
)), -sin(real(&a
))*sinh(imag(&a
))));
74 push( complex(&a
,tan(real(&a
)),0.0) );
76 den
= cos(2*real(&a
))+cosh(2*imag(&a
));
82 push( complex(&a
,sin(2*real(&a
))/den
, sinh(2*imag(&a
))/den
) );
89 register double alpha
, beta
, x
, y
;
91 x
= real(&a
); y
= imag(&a
);
95 push(complex(&a
,0.0, 0.0));
97 push( complex(&a
,asin(x
),0.0) );
99 beta
= sqrt((x
+ 1)*(x
+ 1) + y
*y
)/2 - sqrt((x
- 1)*(x
- 1) + y
*y
)/2;
100 alpha
= sqrt((x
+ 1)*(x
+ 1) + y
*y
)/2 + sqrt((x
- 1)*(x
- 1) + y
*y
)/2;
101 push( complex(&a
,asin(beta
), log(alpha
+ sqrt(alpha
*alpha
-1))) );
108 register double alpha
, beta
, x
, y
;
110 x
= real(&a
); y
= imag(&a
);
114 push(complex(&a
,0.0, 0.0));
116 push( complex(&a
,acos(x
),0.0) );
118 alpha
= sqrt((x
+ 1)*(x
+ 1) + y
*y
)/2 + sqrt((x
- 1)*(x
- 1) + y
*y
)/2;
119 beta
= sqrt((x
+ 1)*(x
+ 1) + y
*y
)/2 - sqrt((x
- 1)*(x
- 1) + y
*y
)/2;
120 push( complex(&a
,acos(beta
), log(alpha
+ sqrt(alpha
*alpha
-1))) );
127 register double x
, y
;
129 x
= real(&a
); y
= imag(&a
);
131 push( complex(&a
,atan(x
), 0.0) );
132 else if (x
== 0.0 && fabs(y
) == 1.0) {
134 push(complex(&a
,0.0, 0.0));
136 push( complex(&a
,atan(2*x
/(1-x
*x
-y
*y
)),
137 log((x
*x
+(y
+1)*(y
+1))/(x
*x
+(y
-1)*(y
-1)))/4) );
144 push( complex(&a
,sinh(real(&a
))*cos(imag(&a
)), cosh(real(&a
))*sin(imag(&a
))) );
151 push( complex(&a
,cosh(real(&a
))*cos(imag(&a
)), sinh(real(&a
))*sin(imag(&a
))) );
159 den
= cosh(2*real(&a
)) + cos(2*imag(&a
));
160 push( complex(&a
,sinh(2*real(&a
))/den
, sin(2*imag(&a
))/den
) );
166 push( integer(&a
,(int)real(pop(&a
))) );
176 push( integer(&a
,abs(a
.v
.int_val
)) );
179 push( complex(&a
,magnitude(&a
), 0.0) );
189 push( integer(&a
,(a
.v
.int_val
> 0) ? 1 :
190 (a
.v
.int_val
< 0) ? -1 : 0) );
193 push( integer(&a
,(a
.v
.cmplx_val
.real
> 0.0) ? 1 :
194 (a
.v
.cmplx_val
.real
< 0.0) ? -1 : 0) );
203 register double mag
, ang
;
205 mag
= sqrt(magnitude(&a
));
206 if (imag(&a
) == 0.0 && real(&a
) < 0.0)
207 push( complex(&a
,0.0,mag
) );
210 if ( (ang
= angle(&a
)) < 0.0)
213 push( complex(&a
,mag
*cos(ang
), mag
*sin(ang
)) );
221 register double mag
, ang
;
225 push( complex(&a
,mag
*cos(ang
), mag
*sin(ang
)) );
232 register double l10
;;
234 l10
= log(10.0); /***** replace with a constant! ******/
235 push( complex(&a
,log(magnitude(&a
))/l10
, angle(&a
)/l10
) );
243 push( complex(&a
,log(magnitude(&a
)), angle(&a
)) );
247 f_besj0() /* j0(a) = sin(a)/a */
257 f_besj1() /* j1(a) = sin(a)/(a**2) - cos(a)/a */
274 f_besy0() /* y0(a) = -cos(a)/a */
285 f_besy1() /* y1(a) = -cos(a)/(a**2) - sin(a)/a */
311 push( integer(&a
,(int)floor((double)a
.v
.int_val
)));
314 push( complex(&a
,floor(a
.v
.cmplx_val
.real
),
315 floor(a
.v
.cmplx_val
.imag
)) );
322 push( integer(&a
,(int)lrand48()));
329 srand48( (long) a
.v
.int_val
);
341 push( integer(&a
,(int)ceil((double)a
.v
.int_val
)));
344 push( complex(&a
,ceil(a
.v
.cmplx_val
.real
), ceil(a
.v
.cmplx_val
.imag
)) );
355 y = gamma(real(pop(&a)));
358 push( integer(&a,0) );
361 push( complex(&a,signgam * exp(y),0.0) );
365 /****************************************************************************/