diff options
| author | Poul-Henning Kamp <phk@FreeBSD.org> | 2002-05-13 13:31:20 +0000 |
|---|---|---|
| committer | Poul-Henning Kamp <phk@FreeBSD.org> | 2002-05-13 13:31:20 +0000 |
| commit | fd3eff9c020ad7a04e56f33d05458d33df3a6423 (patch) | |
| tree | e9298121dbb9a587719499fa7801999a3d183ad6 /lib | |
| parent | 8f08b6b2eef74f8a6f4d78011e198a5743bdb9d7 (diff) | |
Notes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libstand/qdivrem.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/libstand/qdivrem.c b/lib/libstand/qdivrem.c index c6fd4ebc11d4..584a0b1e67b0 100644 --- a/lib/libstand/qdivrem.c +++ b/lib/libstand/qdivrem.c @@ -303,3 +303,51 @@ __umoddi3(a, b) (void)__qdivrem(a, b, &r); return (r); } + +/* + * Divide two signed quads. + * ??? if -1/2 should produce -1 on this machine, this code is wrong + */ +quad_t +__divdi3(a, b) + quad_t a, b; +{ + u_quad_t ua, ub, uq; + int neg; + + if (a < 0) + ua = -(u_quad_t)a, neg = 1; + else + ua = a, neg = 0; + if (b < 0) + ub = -(u_quad_t)b, neg ^= 1; + else + ub = b; + uq = __qdivrem(ua, ub, (u_quad_t *)0); + return (neg ? -uq : uq); +} + +/* + * Return remainder after dividing two signed quads. + * + * XXX + * If -1/2 should produce -1 on this machine, this code is wrong. + */ +quad_t +__moddi3(a, b) + quad_t a, b; +{ + u_quad_t ua, ub, ur; + int neg; + + if (a < 0) + ua = -(u_quad_t)a, neg = 1; + else + ua = a, neg = 0; + if (b < 0) + ub = -(u_quad_t)b; + else + ub = b; + (void)__qdivrem(ua, ub, &ur); + return (neg ? -ur : ur); +} |
