begin, end
OMhelp is designed to be embedded in computer source code.
In fact, it is language independent and can be can combine source
code files in multiple languages to form one documentation system.
Only the text between a begin
and a $end is processed
by OMhelp.
It is intended that these commands be comments in the language.
Source Code Languages
This example covers all languages that have block comments; e.g.,
C, C++, Java, Python.
near_equal_c.c
Use the editor of your choice to
create the file near_equal_c.c in the
xam directory
with the following contents:
/*
$begin near_equal_c$$
$spell
OMhelp
ifdef
stdio
printf
endif
$$
$section Determine if Two Values Are Nearly Equal$$
$head Syntax$$
$icode%e% = near_equal_c(%x%, %y%, %r%, %a%)%$$
$head Purpose$$
Returns true,
if $icode x$$ is nearly equal to $icode y$$ and false otherwise.
$head x$$
The argument $icode x$$ has prototype
$codei%
double %x%
%$$
$head y$$
The argument $icode y$$ has prototype
$codei%
double %y%
%$$
$head r$$
The relative error criteria $icode r$$ has prototype
$codei%
double %r%
%$$
It must be greater than or equal zero.
The relative error condition is satisfied if
$latex \[
| x - y | \leq r ( |x| + |y| )
\] $$
where $latex \leq$$ denotes less than or equal.
$head a$$
The absolute error criteria $icode a$$ has prototype
$codei%
double %a%
%$$
It must be greater than or equal zero.
The absolute error condition is satisfied if
$latex \[
| x - y | \leq a
\] $$
$head e$$
The return value $icode e$$ has prototype
$codei%
int %e%
%$$
If either the relative or absolute error condition is satisfied,
it is one.
Otherwise, it is zero.
$head Example$$
The following is an example and test of $code near_equal_c$$,
it returns true if the test succeeds and false if it fails:
$verbatim%omh/getstarted/ok_near_equal_c.c%
5%// BEGIN_OK_NEAR_EQUAL%// END_OK_NEAR_EQUAL%0
%$$
$end
---------------------------------------------------------------------------
*/
# include <math.h>
int near_equal_c(double x, double y, double r, double a)
{ double ax = fabs(x);
double ay = fabs(y);
double ad = fabs(x - y);
int e = (ad <= a) | (ad <= r * (ax + ay));
return e;
}
Example In This Web Site
You can view the result of making near_equal_c.c
part of the OMhelp help web site by selecting near_equal_c
.
Input File: omh/getstarted/start_block.omh