|
|
1.1 root 1: .ds ZZ DEVELOPMENT PACKAGE
2: .TH MULDIV 3L "630 MTG"
3: .XE "muldiv()"
4: .SH NAME
5: muldiv \- calculate (a*b)/c accurately
6: .SH SYNOPSIS
7: .ft B
8: #include <dmd.h>
9: .br
10: short muldiv (a, b, c)
11: .br
12: int a, b, c;
13: .SH DESCRIPTION
14: The
15: .I muldiv
16: function
17: is a macro that returns the 16-bit result
18: .IR (a*b)/c .
19: .I (a*b)
20: is calculated to 32 bits to minimize the precision lost.
21: The
22: .I muldiv
23: function
24: is convenient for calculating transformations.
25: .SH EXAMPLE
26: The following subroutine implements the transform(3R) function. It
27: converts a point from window coordinates to screen coordinates:
28: .sp
29: .nf
30: .ft CM
31:
32: #include <dmd.h>
33:
34: Point
35: transform(p)
36: Point p;
37: {
38: Point Do, Dc, ret;
39:
40: Do = Drect.origin;
41: Dc = Drect.corner;
42:
43: ret.x = muldiv(p.x, Dc.x-Do.x, XMAX) + Do.x;
44: ret.y = muldiv(p.y, Dc.y-Do.y, YMAX) + Do.y;
45:
46: return(ret);
47: }
48: .ft 1
49: .fi
50: .P
51: The following subroutine does the opposite of the transform(3R)
52: function. It converts a point from screen coordinates to window
53: coordinates.
54: .nf
55: .ft CM
56:
57: #include <dmd.h>
58:
59: Point
60: untransform(p)
61: Point p;
62: {
63: Point Do, Dc, ret;
64:
65: Do = Drect.origin;
66: Dc = Drect.corner;
67:
68: ret.x = muldiv(p.x-Do.x, XMAX, Dc.x-Do.x);
69: ret.y = muldiv(p.y-Do.y, YMAX, Dc.y-Do.y);
70:
71: return(ret);
72: }
73: .fi
74: .ft R
75: .SH SEE ALSO
76: globals(3R), ptarith(3R), transform(3R/3L).
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.