Introduction The Delphi "system" unit contains a function called abs( x ) where x may be real or integer.This function returns the absolute value of x, so
abs(15) = 15
if x > 0 then abs(x) = x 1. Distances While moving the mouse over the screen, (x,y) coordinates are generated.Say, successive mouseclicks save these coordinates in (x1,y1) and (x2,y2). We want variables dx and dy to hold the horizontal and vertical distances between points 1 and 2. This code takes does the job
dy := abs(y1  y2) To avoid negative distances, if statements could be used, but this approach is slower. Modern processors execute instructions in pipelines that read codes ahead. If statements disrupt this proces, the pipeline has to be rebuild when instruction flow alters. 2. Lower boundery Say we use a variable x in our program and x is not allowed to be negative.This means, that a negative value of x must be rounded to zero. An if statement may do the job, but an abs( ) function can do the job faster. The understand how this works we first have a look at the graph of the function y=abs(x). In position (0,0) the graph has a sharp bend. This is a unique property of the abs function. Other functions like polynomials, sin, cos, tan, log have smooth graphs, no bends. All following results are obtained from the above graph. The bend may not be positioned at (0,0). Therefore we first introduce a few trics to manipulate graphs in general: shifting, scaling, reflection. If in a general function y = f(x) , the x is replaced by (x1) then the graph will shift 1 scale to the right. This is obvious: say point P(p,q) is on the graph y = f(x) , which means that q = f(p). However if x is replaced by x1 then not p = x, but p = x 1 is the case so: x = p + 1. p is changed to p + 1, indicating a shift of 1 scale to the right. In a similar way we conclude that replacing y by (y1) shifts the graph 1 scale up in vertical direction. Replacing x by (x1) shifts the graph 1 scale left, replacing y by (y1) shifts the graph 1 scale down. If in the function y = f(x) , x is replaced by x/2 then the graph will expand by a factor 2 in horizontal direction, so, relative to the y axis. (the y axis has the equation x = 0) similar, if y is replaced by y/2 the graph expands by a factor 2 in the y direction. Finally, if we replace x by (x), the graph is reflected in the yaxis. Replacing y by (y) reflects the graph in the xaxis. With the above knowlegde in mind we may position the bend (0,0) of function y = abs(x). In the graph below
y = abs(x  3) + 2 y = abs(x) and y = x. We plot function y = abs(x) + x This is cured by replacing y by 2y, which let the function shrink by a factor 2 in vertical direction. So the result is
y = 0,5(abs(x) + x) Point (0,0) must be shifted to (10,10). Therefore we replace x by (x10) and y by (y10), so
y = 0,5(abs(x10) + x) + 5 3.Upper boundary For an upper boundary we reflect the graph in the yaxis, by replacing x by (x):
Reflection again, now in the xaxis ( y replaced by y)
y = 0,5(abs(x) x) ................so y = 0,5(x  abs(x)) The bending point may be shifted to any position as illustrated before. The factor 0.5 adjusts the slope. Say we want an upper boundary of 100. Point (0,0) has to be shifted to (100,100) which is achieved by replacing x by (x100) and y by (y100)
y = 0,5(x  abs(x100)) + 50 4.Upper and Lower boundaries We plot function y = 0,5(abs(x+1)  abs(x1))Note: the scale is 0.2 Below x = 1 the function has a lower boundary of 1 and after x = 1 there is an upper boundary of 1. How to establish other boundaries? Let's start with function y = 0,5(abs(x+v)  abs(xv)) For x < v we may write:
The distance between these boundaries is b  a. So v = (ba)/2 for temporary boundaries v and v. However, the upper boundary is b, not (ba)/2 so a shift is needed of (end  start), b  v
so, replace x by x(a+b)/2 and y by y(a+b)/2
y  (a+b)/2 = 0,5(abs(x(a+b)/2 + (ba)/2)  abs(x(a+b)/2  (ba)/2)) y  (a+b)/2 = 0,5(abs(xa)  abs(xb)) y = 0,5(abs(xa)  abs(xb) + a + b) And without the use of if statements. Pipelines of the processor keep streaming without interruption. My grapher program GraphicsExplorer may be used to show this results. Download the program from http://www.davdata.nl/math/grxpl.html Type y = 0,5(abs(xa)  abs(xb) + a + b) and click "plot". Select (right top) "replace" (not add) and "autoplot". Left or rightclick on the a and b fields to change these constants. Graphics imediately show the new boundaries. Below I summarize the results (y is the clipped value of x): Variable x is given

