125c28e8Piotr Jasiukajtis/*
225c28e8Piotr Jasiukajtis * CDDL HEADER START
325c28e8Piotr Jasiukajtis *
425c28e8Piotr Jasiukajtis * The contents of this file are subject to the terms of the
525c28e8Piotr Jasiukajtis * Common Development and Distribution License (the "License").
625c28e8Piotr Jasiukajtis * You may not use this file except in compliance with the License.
725c28e8Piotr Jasiukajtis *
825c28e8Piotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
925c28e8Piotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
1025c28e8Piotr Jasiukajtis * See the License for the specific language governing permissions
1125c28e8Piotr Jasiukajtis * and limitations under the License.
1225c28e8Piotr Jasiukajtis *
1325c28e8Piotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
1425c28e8Piotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1525c28e8Piotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
1625c28e8Piotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
1725c28e8Piotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
1825c28e8Piotr Jasiukajtis *
1925c28e8Piotr Jasiukajtis * CDDL HEADER END
2025c28e8Piotr Jasiukajtis */
2125c28e8Piotr Jasiukajtis
2225c28e8Piotr Jasiukajtis/*
2325c28e8Piotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
2425c28e8Piotr Jasiukajtis */
2525c28e8Piotr Jasiukajtis/*
2625c28e8Piotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
2725c28e8Piotr Jasiukajtis * Use is subject to license terms.
2825c28e8Piotr Jasiukajtis */
2925c28e8Piotr Jasiukajtis
30ddc0e0bRichard Lowe#pragma weak __remquol = remquol
3125c28e8Piotr Jasiukajtis
3225c28e8Piotr Jasiukajtis#include "libm.h"
3325c28e8Piotr Jasiukajtis#if defined(__SUNPRO_C)
3425c28e8Piotr Jasiukajtis#include <sunmath.h>			/* fabsl */
3525c28e8Piotr Jasiukajtis#endif
3625c28e8Piotr Jasiukajtis/* INDENT OFF */
3725c28e8Piotr Jasiukajtisstatic const int
3825c28e8Piotr Jasiukajtis	is = -0x7fffffff - 1,
3925c28e8Piotr Jasiukajtis	im = 0x0000ffff,
4025c28e8Piotr Jasiukajtis	iu = 0x00010000;
4125c28e8Piotr Jasiukajtis
4225c28e8Piotr Jasiukajtisstatic const long double zero = 0.0L, one = 1.0L;
4325c28e8Piotr Jasiukajtis/* INDENT ON */
4425c28e8Piotr Jasiukajtis
4525c28e8Piotr Jasiukajtis#if defined(__sparc)
4625c28e8Piotr Jasiukajtis#define	__H0(x)	((int *) &x)[0]
4725c28e8Piotr Jasiukajtis#define	__H1(x)	((int *) &x)[1]
4825c28e8Piotr Jasiukajtis#define	__H2(x)	((int *) &x)[2]
4925c28e8Piotr Jasiukajtis#define	__H3(x)	((int *) &x)[3]
5025c28e8Piotr Jasiukajtis#else
5125c28e8Piotr Jasiukajtis#error Unsupported architecture
5225c28e8Piotr Jasiukajtis#endif
5325c28e8Piotr Jasiukajtis
5425c28e8Piotr Jasiukajtis/*
5525c28e8Piotr Jasiukajtis * On entrance: *quo is initialized to 0, x finite and y non-zero & ordered
5625c28e8Piotr Jasiukajtis */
5725c28e8Piotr Jasiukajtisstatic long double
5825c28e8Piotr Jasiukajtisfmodquol(long double x, long double y, int *quo) {
5925c28e8Piotr Jasiukajtis	long double a, b;
6025c28e8Piotr Jasiukajtis	int n, ix, iy, k, sx, sq, m;
6125c28e8Piotr Jasiukajtis	int hx;
6225c28e8Piotr Jasiukajtis	int x0, y0, z0, carry;
6325c28e8Piotr Jasiukajtis	unsigned x1, x2, x3, y1, y2, y3, z1, z2, z3;
6425c28e8Piotr Jasiukajtis
6525c28e8Piotr Jasiukajtis	hx = __H0(x);
6625c28e8Piotr Jasiukajtis	x1 = __H1(x);
6725c28e8Piotr Jasiukajtis	x2 = __H2(x);
6825c28e8Piotr Jasiukajtis	x3 = __H3(x);
6925c28e8Piotr Jasiukajtis	y0 = __H0(y);
7025c28e8Piotr Jasiukajtis	y1 = __H1(y);
7125c28e8Piotr Jasiukajtis	y2 = __H2(y);
7225c28e8Piotr Jasiukajtis	y3 = __H3(y);
7325c28e8Piotr Jasiukajtis
7425c28e8Piotr Jasiukajtis	sx = hx & is;
7525c28e8Piotr Jasiukajtis	sq = (hx ^ y0) & is;
7625c28e8Piotr Jasiukajtis	x0 = hx ^ sx;
7725c28e8Piotr Jasiukajtis	y0 &= ~0x80000000;
7825c28e8Piotr Jasiukajtis
7925c28e8Piotr Jasiukajtis	a = fabsl(x);
8025c28e8Piotr Jasiukajtis	b = fabsl(y);
8125c28e8Piotr Jasiukajtis	if (a <= b) {
8225c28e8Piotr Jasiukajtis		if (a < b)
8325c28e8Piotr Jasiukajtis			return (x);
8425c28e8Piotr Jasiukajtis		else {
8525c28e8Piotr Jasiukajtis			*quo = 1 + (sq >> 30);
8625c28e8Piotr Jasiukajtis			return (zero * x);
8725c28e8Piotr Jasiukajtis		}
8825c28e8Piotr Jasiukajtis	}
8925c28e8Piotr Jasiukajtis	/* determine ix = ilogbl(x) */
9025c28e8Piotr Jasiukajtis	if (x0 < iu) {		/* subnormal x */
9125c28e8Piotr Jasiukajtis		ix = 0;
9225c28e8Piotr Jasiukajtis		ix = -16382;
9325c28e8Piotr Jasiukajtis		while (x0 == 0) {
9425c28e8Piotr Jasiukajtis			ix -= 16;
9525c28e8Piotr Jasiukajtis			x0 = x1 >> 16;
9625c28e8Piotr Jasiukajtis			x1 = (x1 << 16) | (x2 >> 16);
9725c28e8Piotr Jasiukajtis			x2 = (x2 << 16) | (x3 >> 16);
9825c28e8Piotr Jasiukajtis			x3 = (x3 << 16);
9925c28e8Piotr Jasiukajtis		}
10025c28e8Piotr Jasiukajtis		while (x0 < iu) {
10125c28e8Piotr Jasiukajtis			ix -= 1;
10225c28e8Piotr Jasiukajtis			x0 = (x0 << 1) | (x1 >> 31);
10325c28e8Piotr Jasiukajtis			x1 = (x1 << 1) | (x2 >> 31);
10425c28e8Piotr Jasiukajtis			x2 = (x2 << 1) | (x3 >> 31);
10525c28e8Piotr Jasiukajtis			x3 <<= 1;
10625c28e8Piotr Jasiukajtis		}
10725c28e8Piotr Jasiukajtis	} else {
10825c28e8Piotr Jasiukajtis		ix = (x0 >> 16) - 16383;
10925c28e8Piotr Jasiukajtis		x0 = iu | (x0 & im);
11025c28e8Piotr Jasiukajtis	}
11125c28e8Piotr Jasiukajtis
11225c28e8Piotr Jasiukajtis	/* determine iy = ilogbl(y) */
11325c28e8Piotr Jasiukajtis	if (y0 < iu) {		/* subnormal y */
11425c28e8Piotr Jasiukajtis		iy = -16382;
11525c28e8Piotr Jasiukajtis		while (y0 == 0) {
11625c28e8Piotr Jasiukajtis			iy -= 16;
11725c28e8Piotr Jasiukajtis			y0 = y1 >> 16;
11825c28e8Piotr Jasiukajtis			y1 = (y1 << 16) | (y2 >> 16);
11925c28e8Piotr Jasiukajtis			y2 = (y2 << 16) | (y3 >> 16);
12025c28e8Piotr Jasiukajtis			y3 = (y3 << 16);
12125c28e8Piotr Jasiukajtis		}
12225c28e8Piotr Jasiukajtis		while (y0 < iu) {
12325c28e8Piotr Jasiukajtis			iy -= 1;
12425c28e8Piotr Jasiukajtis			y0 = (y0 << 1) | (y1 >> 31);
12525c28e8Piotr Jasiukajtis			y1 = (y1 << 1) | (y2 >> 31);
12625c28e8Piotr Jasiukajtis			y2 = (y2 << 1) | (y3 >> 31);
12725c28e8Piotr Jasiukajtis			y3 <<= 1;
12825c28e8Piotr Jasiukajtis		}
12925c28e8Piotr Jasiukajtis	} else {
13025c28e8Piotr Jasiukajtis		iy = (y0 >> 16) - 16383;
13125c28e8Piotr Jasiukajtis		y0 = iu | (y0 & im);
13225c28e8Piotr Jasiukajtis	}
13325c28e8Piotr Jasiukajtis
13425c28e8Piotr Jasiukajtis
13525c28e8Piotr Jasiukajtis	/* fix point fmod */
13625c28e8Piotr Jasiukajtis	n = ix - iy;
13725c28e8Piotr Jasiukajtis	m = 0;
13825c28e8Piotr Jasiukajtis	while (n--) {
13925c28e8Piotr Jasiukajtis		while (x0 == 0 && n >= 16) {
14025c28e8Piotr Jasiukajtis			m <<= 16;
14125c28e8Piotr Jasiukajtis			n -= 16;
14225c28e8Piotr Jasiukajtis			x0 = x1 >> 16;
14325c28e8Piotr Jasiukajtis			x1 = (x1 << 16) | (x2 >> 16);
14425c28e8Piotr Jasiukajtis			x2 = (x2 << 16) | (x3 >> 16);
14525c28e8Piotr Jasiukajtis			x3 = (x3 << 16);
14625c28e8Piotr Jasiukajtis		}
14725c28e8Piotr Jasiukajtis		while (x0 < iu && n >= 1) {
14825c28e8Piotr Jasiukajtis			m += m;
14925c28e8Piotr Jasiukajtis			n -= 1;
15025c28e8Piotr Jasiukajtis			x0 = (x0 << 1) | (x1 >> 31);
15125c28e8Piotr Jasiukajtis			x1 = (x1 << 1) | (x2 >> 31);
15225c28e8Piotr Jasiukajtis			x2 = (x2 << 1) | (x3 >> 31);
15325c28e8Piotr Jasiukajtis			x3 = (x3 << 1);
15425c28e8Piotr Jasiukajtis		}
15525c28e8Piotr Jasiukajtis		carry = 0;
15625c28e8Piotr Jasiukajtis		z3 = x3 - y3;
15725c28e8Piotr Jasiukajtis		carry = z3 > x3;
15825c28e8Piotr Jasiukajtis		if (carry == 0) {
15925c28e8Piotr Jasiukajtis			z2 = x2 - y2;
16025c28e8Piotr Jasiukajtis			carry = z2 > x2;
16125c28e8Piotr Jasiukajtis		} else {
16225c28e8Piotr Jasiukajtis			z2 = x2 - y2 - 1;
16325c28e8Piotr Jasiukajtis			carry = z2 >= x2;
16425c28e8Piotr Jasiukajtis		}
16525c28e8Piotr Jasiukajtis		if (carry == 0) {
16625c28e8Piotr Jasiukajtis			z1 = x1 - y1;
16725c28e8Piotr Jasiukajtis			carry = z1 > x1;
16825c28e8Piotr Jasiukajtis		} else {
16925c28e8Piotr Jasiukajtis			z1 = x1 - y1 - 1;
17025c28e8Piotr Jasiukajtis			carry = z1 >= x1;
17125c28e8Piotr Jasiukajtis		}
17225c28e8Piotr Jasiukajtis		z0 = x0 - y0 - carry;
17325c28e8Piotr Jasiukajtis		if (z0 < 0) {	/* double x */
17425c28e8Piotr Jasiukajtis			x0 = x0 + x0 + ((x1 & is) != 0);
17525c28e8Piotr Jasiukajtis			x1 = x1 + x1 + ((x2 & is) != 0);
17625c28e8Piotr Jasiukajtis			x2 = x2 + x2 + ((x3 & is) != 0);
17725c28e8Piotr Jasiukajtis			x3 = x3 + x3;
17825c28e8Piotr Jasiukajtis			m += m;
17925c28e8Piotr Jasiukajtis		} else {
18025c28e8Piotr Jasiukajtis			m += 1;
18125c28e8Piotr Jasiukajtis			if (z0 == 0) {
18225c28e8Piotr Jasiukajtis				if ((z1 | z2 | z3) == 0) {
18325c28e8Piotr Jasiukajtis					/* 0: we are done */
18425c28e8Piotr Jasiukajtis					if (n < 31)
18525c28e8Piotr Jasiukajtis						m <<= (1 + n);
18625c28e8Piotr Jasiukajtis					else
18725c28e8Piotr Jasiukajtis						m = 0;
18825c28e8Piotr Jasiukajtis					m &= ~0x80000000;
18925c28e8Piotr Jasiukajtis					*quo = sq >= 0 ? m : -m;
19025c28e8Piotr Jasiukajtis					__H0(a) = hx & is;
19125c28e8Piotr Jasiukajtis					__H1(a) = __H2(a) = __H3(a) = 0;
19225c28e8Piotr Jasiukajtis					return (a);
19325c28e8Piotr Jasiukajtis				}
19425c28e8Piotr Jasiukajtis			}
19525c28e8Piotr Jasiukajtis			/* x = z << 1 */
19625c28e8Piotr Jasiukajtis			z0 = z0 + z0 + ((z1 & is) != 0);
19725c28e8Piotr Jasiukajtis			z1 = z1 + z1 + ((z2 & is) != 0);
19825c28e8Piotr Jasiukajtis			z2 = z2 + z2 + ((z3 & is) != 0);
19925c28e8Piotr Jasiukajtis			z3 = z3 + z3;
20025c28e8Piotr Jasiukajtis			x0 = z0;
20125c28e8Piotr Jasiukajtis			x1 = z1;
20225c28e8Piotr Jasiukajtis			x2 = z2;
20325c28e8Piotr Jasiukajtis			x3 = z3;
20425c28e8Piotr Jasiukajtis			m += m;
20525c28e8Piotr Jasiukajtis		}
20625c28e8Piotr Jasiukajtis	}
20725c28e8Piotr Jasiukajtis	carry = 0;
20825c28e8Piotr Jasiukajtis	z3 = x3 - y3;
20925c28e8Piotr Jasiukajtis	carry = z3 > x3;
21025c28e8Piotr Jasiukajtis	if (carry == 0) {
21125c28e8Piotr Jasiukajtis		z2 = x2 - y2;
21225c28e8Piotr Jasiukajtis		carry = z2 > x2;
21325c28e8Piotr Jasiukajtis	} else {
21425c28e8Piotr Jasiukajtis		z2 = x2 - y2 - 1;
21525c28e8Piotr Jasiukajtis		carry = z2 >= x2;
21625c28e8Piotr Jasiukajtis	}
21725c28e8Piotr Jasiukajtis	if (carry == 0) {
21825c28e8Piotr Jasiukajtis		z1 = x1 - y1;
21925c28e8Piotr Jasiukajtis		carry = z1 > x1;
22025c28e8Piotr Jasiukajtis	} else {
22125c28e8Piotr Jasiukajtis		z1 = x1 - y1 - 1;
22225c28e8Piotr Jasiukajtis		carry = z1 >= x1;
22325c28e8Piotr Jasiukajtis	}
22425c28e8Piotr Jasiukajtis	z0 = x0 - y0 - carry;
22525c28e8Piotr Jasiukajtis	if (z0 >= 0) {
22625c28e8Piotr Jasiukajtis		x0 = z0;
22725c28e8Piotr Jasiukajtis		x1 = z1;
22825c28e8Piotr Jasiukajtis		x2 = z2;
22925c28e8Piotr Jasiukajtis		x3 = z3;
23025c28e8Piotr Jasiukajtis		m += 1;
23125c28e8Piotr Jasiukajtis	}
23225c28e8Piotr Jasiukajtis	m &= ~0x80000000;
23325c28e8Piotr Jasiukajtis	*quo = sq >= 0 ? m : -m;
23425c28e8Piotr Jasiukajtis
23525c28e8Piotr Jasiukajtis	/* convert back to floating value and restore the sign */
23625c28e8Piotr Jasiukajtis	if ((x0 | x1 | x2 | x3) == 0) {
23725c28e8Piotr Jasiukajtis		__H0(a) = hx & is;
23825c28e8Piotr Jasiukajtis		__H1(a) = __H2(a) = __H3(a) = 0;
23925c28e8Piotr Jasiukajtis		return (a);
24025c28e8Piotr Jasiukajtis	}
24125c28e8Piotr Jasiukajtis	while (x0 < iu) {
24225c28e8Piotr Jasiukajtis		if (x0 == 0) {
24325c28e8Piotr Jasiukajtis			iy -= 16;
24425c28e8Piotr Jasiukajtis			x0 = x1 >> 16;
24525c28e8Piotr Jasiukajtis			x1 = (x1 << 16) | (x2 >> 16);
24625c28e8Piotr Jasiukajtis			x2 = (x2 << 16) | (x3 >> 16);
24725c28e8Piotr Jasiukajtis			x3 = (x3 << 16);
24825c28e8Piotr Jasiukajtis		} else {
24925c28e8Piotr Jasiukajtis			x0 = x0 + x0 + ((x1 & is) != 0);
25025c28e8Piotr Jasiukajtis			x1 = x1 + x1 + ((x2 & is) != 0);
25125c28e8Piotr Jasiukajtis			x2 = x2 + x2 + ((x3 & is) != 0);
25225c28e8Piotr Jasiukajtis			x3 = x3 + x3;
25325c28e8Piotr Jasiukajtis			iy -= 1;
25425c28e8Piotr Jasiukajtis		}
25525c28e8Piotr Jasiukajtis	}
25625c28e8Piotr Jasiukajtis
25725c28e8Piotr Jasiukajtis	/* normalize output */
25825c28e8Piotr Jasiukajtis	if (iy >= -16382) {
25925c28e8Piotr Jasiukajtis		__H0(a) = sx | (x0 - iu) | ((iy + 16383) << 16);
26025c28e8Piotr Jasiukajtis		__H1(a) = x1;
26125c28e8Piotr Jasiukajtis		__H2(a) = x2;
26225c28e8Piotr Jasiukajtis		__H3(a) = x3;
26325c28e8Piotr Jasiukajtis	} else {		/* subnormal output */
26425c28e8Piotr Jasiukajtis		n = -16382 - iy;
26525c28e8Piotr Jasiukajtis		k = n & 31;
26625c28e8Piotr Jasiukajtis		if (k <= 16) {
26725c28e8Piotr Jasiukajtis			x3 = (x2 << (32 - k)) | (x3 >> k);
26825c28e8Piotr Jasiukajtis			x2 = (x1 << (32 - k)) | (x2 >> k);
26925c28e8Piotr Jasiukajtis			x1 = (x0 << (32 - k)) | (x1 >> k);
27025c28e8Piotr Jasiukajtis			x0 >>= k;
27125c28e8Piotr Jasiukajtis		} else {
27225c28e8Piotr Jasiukajtis			x3 = (x2 << (32 - k)) | (x3 >> k);
27325c28e8Piotr Jasiukajtis			x2 = (x1 << (32 - k)) | (x2 >> k);
27425c28e8Piotr Jasiukajtis			x1 = (x0 << (32 - k)) | (x1 >> k);
27525c28e8Piotr Jasiukajtis			x0 = 0;
27625c28e8Piotr Jasiukajtis		}
27725c28e8Piotr Jasiukajtis		while (n >= 32) {
27825c28e8Piotr Jasiukajtis			n -= 32;
27925c28e8Piotr Jasiukajtis			x3 = x2;
28025c28e8Piotr Jasiukajtis			x2 = x1;
28125c28e8Piotr Jasiukajtis			x1 = x0;
28225c28e8Piotr Jasiukajtis			x0 = 0;
28325c28e8Piotr Jasiukajtis		}
28425c28e8Piotr Jasiukajtis		__H0(a) = x0 | sx;
28525c28e8Piotr Jasiukajtis		__H1(a) = x1;
28625c28e8Piotr Jasiukajtis		__H2(a) = x2;
28725c28e8Piotr Jasiukajtis		__H3(a) = x3;
28825c28e8Piotr Jasiukajtis		a *= one;
28925c28e8Piotr Jasiukajtis	}
29025c28e8Piotr Jasiukajtis	return (a);
29125c28e8Piotr Jasiukajtis}
29225c28e8Piotr Jasiukajtis
29325c28e8Piotr Jasiukajtislong double
29425c28e8Piotr Jasiukajtisremquol(long double x, long double y, int *quo) {
29525c28e8Piotr Jasiukajtis	int hx, hy, sx, sq;
29625c28e8Piotr Jasiukajtis	long double v;
29725c28e8Piotr Jasiukajtis
29825c28e8Piotr Jasiukajtis	hx = __H0(x);		/* high word of x */
29925c28e8Piotr Jasiukajtis	hy = __H0(y);		/* high word of y */
30025c28e8Piotr Jasiukajtis	sx = hx & is;		/* sign of x */
30125c28e8Piotr Jasiukajtis	sq = (hx ^ hy) & is;	/* sign of x/y */
30225c28e8Piotr Jasiukajtis	hx ^= sx;		/* |x| */
30325c28e8Piotr Jasiukajtis	hy &= ~0x80000000;
30425c28e8Piotr Jasiukajtis
30525c28e8Piotr Jasiukajtis	/* purge off exception values */
30625c28e8Piotr Jasiukajtis	*quo = 0;
30725c28e8Piotr Jasiukajtis	/* y=0, y is NaN, x is NaN or inf */
30825c28e8Piotr Jasiukajtis	if (y == 0.0L || y != y || hx >= 0x7fff0000)
30925c28e8Piotr Jasiukajtis		return ((x * y) / (x * y));
31025c28e8Piotr Jasiukajtis
31125c28e8Piotr Jasiukajtis	y = fabsl(y);
31225c28e8Piotr Jasiukajtis	x = fabsl(x);
31325c28e8Piotr Jasiukajtis	if (hy <= 0x7ffdffff) {
31425c28e8Piotr Jasiukajtis		x = fmodquol(x, y + y, quo);
31525c28e8Piotr Jasiukajtis		*quo = ((*quo) & 0x3fffffff) << 1;
31625c28e8Piotr Jasiukajtis	}
31725c28e8Piotr Jasiukajtis	if (hy < 0x00020000) {
31825c28e8Piotr Jasiukajtis		if (x + x > y) {
31925c28e8Piotr Jasiukajtis			*quo += 1;
32025c28e8Piotr Jasiukajtis			if (x == y)
32125c28e8Piotr Jasiukajtis				x = zero;
32225c28e8Piotr Jasiukajtis			else
32325c28e8Piotr Jasiukajtis				x -= y;
32425c28e8Piotr Jasiukajtis			if (x + x >= y) {
32525c28e8Piotr Jasiukajtis				x -= y;
32625c28e8Piotr Jasiukajtis				*quo += 1;
32725c28e8Piotr Jasiukajtis			}
32825c28e8Piotr Jasiukajtis		}
32925c28e8Piotr Jasiukajtis	} else {
33025c28e8Piotr Jasiukajtis		v = 0.5L * y;
33125c28e8Piotr Jasiukajtis		if (x > v) {
33225c28e8Piotr Jasiukajtis			*quo += 1;
33325c28e8Piotr Jasiukajtis			if (x == y)
33425c28e8Piotr Jasiukajtis				x = zero;
33525c28e8Piotr Jasiukajtis			else
33625c28e8Piotr Jasiukajtis				x -= y;
33725c28e8Piotr Jasiukajtis			if (x >= v) {
33825c28e8Piotr Jasiukajtis				x -= y;
33925c28e8Piotr Jasiukajtis				*quo += 1;
34025c28e8Piotr Jasiukajtis			}
34125c28e8Piotr Jasiukajtis		}
34225c28e8Piotr Jasiukajtis	}
34325c28e8Piotr Jasiukajtis	if (sq != 0)
34425c28e8Piotr Jasiukajtis		*quo = -(*quo);
34525c28e8Piotr Jasiukajtis	return (sx == 0 ? x : -x);
34625c28e8Piotr Jasiukajtis}
347