Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #if !defined(__alpha)
00049 # include <ieeefp.h>
00050 #endif
00051 #include "quad.h"
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 qcomplex __cqdiv(long double xqreal, long double xqimag, long double yqreal, long double yqimag)
00065 {
00066 qcomplex result;
00067
00068 #if defined(__alpha)
00069
00070 result.qreal = 0;
00071 result.qimag = 0;
00072
00073 #else
00074
00075 long double tmp;
00076 unsigned int m, n;
00077 fp_except oldmask;
00078 fp_except oldsticky;
00079
00080 if ((xqreal != xqreal) || (xqimag != xqimag) ||
00081 (yqreal != yqreal) || (yqimag != yqimag)) {
00082 result.qreal = __libm_qnan_ld;
00083 result.qimag = __libm_qnan_ld;
00084 return result;
00085 }
00086
00087 if ((yqreal == 0.0L) && (yqimag == 0.0L)) {
00088 result.qreal = xqreal/__libm_zero_ld;
00089 result.qimag = xqimag/__libm_zero_ld;
00090 return result;
00091 }
00092
00093 if (yqreal == 0.0L) {
00094 result.qreal = xqimag/yqimag;
00095 result.qimag = -(xqreal/yqimag);
00096 return result;
00097 }
00098
00099 if (yqimag == 0.0L) {
00100 result.qreal = xqreal/yqreal;
00101 result.qimag = xqimag/yqreal;
00102 return result;
00103 }
00104
00105 if (__qabs(yqreal) <= __qabs(yqimag)) {
00106
00107
00108
00109
00110
00111 oldmask = fpgetmask();
00112 oldsticky = fpgetsticky();
00113
00114
00115 fpsetmask(oldmask & ~FP_X_UFL);
00116
00117 tmp = yqreal/yqimag;
00118
00119
00120 fpsetmask(oldmask);
00121 fpsetsticky(oldsticky);
00122
00123 result.qreal = (xqimag + xqreal*tmp)/(yqimag + yqreal*tmp);
00124 result.qimag = (-xqreal + xqimag*tmp)/(yqimag + yqreal*tmp);
00125 return result;
00126 }
00127
00128
00129
00130
00131
00132 oldmask = fpgetmask();
00133 oldsticky = fpgetsticky();
00134
00135
00136 fpsetmask(oldmask & ~FP_X_UFL);
00137
00138 tmp = yqimag/yqreal;
00139
00140
00141 fpsetmask(oldmask);
00142 fpsetsticky(oldsticky);
00143
00144 result.qreal = (xqreal + xqimag*tmp)/(yqreal + yqimag*tmp);
00145 result.qimag = (xqimag - xqreal*tmp)/(yqreal + yqimag*tmp);
00146
00147 #endif
00148
00149 return result;
00150 }
00151
00152 void __cq_div(qcomplex *result, qcomplex *x, qcomplex *y)
00153 {
00154 *result = __cqdiv(x->qreal, x->qimag, y->qreal, y->qimag);
00155 }