double __adddf3(double a, double b) { double_t da; double_t db; double_t res; da.val = a; db.val = b; if (da.data.parts.sign != db.data.parts.sign) { if (da.data.parts.sign) { da.data.parts.sign = 0; res.data = sub_double(db.data, da.data); return res.val; } db.data.parts.sign = 0; res.data = sub_double(da.data, db.data); return res.val; } res.data = add_double(da.data, db.data); return res.val; }
static void add_long(void *opaque, void *parent, const char *name, long v) { if(v <= INT32_MAX && v >= INT32_MIN && INT_FITS_IN_JSVAL(v)) add_item(opaque, parent, name, INT_TO_JSVAL(v)); else add_double(opaque, parent, name, v); }
int main() { unsigned int i; double a = 0.0; for (i = 0; i < 1000000; i++) { a += 1.0; add_double(a, a); } printf("%f\n",a); }
void setup_torus_fields (double probe_radius, struct pair *pair_ptr, double torus_center[3], double *return_radius, double torus_axis[3]) { int k; double root1, root2, asymmetry; double distance12, distance12_squared; double radius1, radius2, torus_radius; double *sphere1_center, *sphere2_center; char message[MAXLINE]; struct sphere *sphere1, *sphere2; struct cept *ex; sphere1 = pair_ptr -> sph[0]; sphere2 = pair_ptr -> sph[1]; if (sphere1 >= sphere2) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } /* transfer info to local variables */ sphere1_center = sphere1 -> center; radius1 = sphere1 -> radius; sphere2_center = sphere2 -> center; radius2 = sphere2 -> radius; /* geometric computations for torus */ for (k = 0; k < 3; k++) torus_axis[k] = *(sphere2_center + k) - *(sphere1_center + k); distance12 = norm (torus_axis); if (distance12 <= 0.0) { ex = new_cept (GEOMETRY_ERROR, DEGENERACY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "coincident atoms"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } distance12_squared = distance12 * distance12; if (distance12_squared <= 0.0) { ex = new_cept (GEOMETRY_ERROR, DEGENERACY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "coincident atoms"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } for (k = 0; k < 3; k++) torus_axis[k] /= distance12; root1 = (radius1 + radius2 + 2 * probe_radius) * (radius1 + radius2 + 2 * probe_radius) - distance12_squared; if (root1 < 0.0) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "inconsistent existence of torus"); add_atom (ex, sphere1); add_atom (ex, sphere2); add_double (ex, "root1", root1); return; } root1 = sqrt (root1); root2 = distance12_squared - (radius1 - radius2) * (radius1 - radius2); if (root2 < 0.0) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "inconsistent existence of torus"); add_atom (ex, sphere1); add_atom (ex, sphere2); add_double (ex, "root2", root2); return; } root2 = sqrt (root2); torus_radius = 0.5 * root1 * root2 / distance12; if (torus_radius <= 0) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "inconsistent existence of torus"); add_atom (ex, sphere1); add_atom (ex, sphere2); add_double (ex, "torus_radius", torus_radius); return; } asymmetry = (radius1 + probe_radius) * (radius1 + probe_radius) - (radius2 + probe_radius) * (radius2 + probe_radius); for (k = 0; k < 3; k++) torus_center[k] = 0.5 * (*(sphere1_center + k) + *(sphere2_center + k)) + 0.5 * torus_axis[k] * asymmetry / distance12; *return_radius = torus_radius; return; }