rsc | cfa37a7 | 2004-04-10 18:53:55 +0000 | [diff] [blame] | 1 | .TH MULDIV 3 |
| 2 | .SH NAME |
| 3 | muldiv, umuldiv \- high-precision multiplication and division |
| 4 | .SH SYNOPSIS |
| 5 | .B #include <u.h> |
| 6 | .br |
| 7 | .B #include <libc.h> |
| 8 | .PP |
| 9 | .B |
rsc | c8b6342 | 2005-01-13 04:49:19 +0000 | [diff] [blame] | 10 | long muldiv(long a, long b, long c) |
rsc | cfa37a7 | 2004-04-10 18:53:55 +0000 | [diff] [blame] | 11 | .PP |
| 12 | .B |
| 13 | ulong umuldiv(ulong a, ulong b, ulong c) |
| 14 | .SH DESCRIPTION |
| 15 | .I Muldiv |
| 16 | returns |
| 17 | .BR a*b/c , |
| 18 | using a |
| 19 | .B vlong |
| 20 | to hold the intermediate result. |
| 21 | .I Umuldiv |
| 22 | is the equivalent for unsigned integers. |
| 23 | They can be used to scale integer values without worry about |
| 24 | overflowing the intermediate result. |
| 25 | .PP |
| 26 | On some architectures, these routines can generate a trap if the |
| 27 | final result does not fit in a |
| 28 | .B long |
| 29 | or |
| 30 | .BR ulong ; |
| 31 | on others they will silently truncate. |