Hi!
This is an example entry for how I think our joined effort to complete the GPC reference could work. The section I am posting is already in existence (`abs'):
@c ----------------------------------------------------------------------------
@node abs @unnumberedsec abs @cindex abs
@unnumberedsubsec Syntax
@smallexample Function abs ( i: @var{integer type} ): @var{integer type}; @end smallexample or @smallexample Function abs ( x: @var{real type} ): @var{real type}; @end smallexample or @smallexample Function abs ( z: @var{complex type} ): @var{real type}; @end smallexample
@unnumberedsubsec Description
Returns the absolute value of the argument:
@smallexample Function abs ( x: @var{some type} ): @var{some type};
begin (* abs *) if x < 0 then abs:= -x else abs:= x; end (* abs *); @end smallexample
@unnumberedsubsec Standards
The function @samp{abs} is defined in ISO-7185 Standard Pascal; its application to complex values is defined in ISO-10206 Extended Pascal.
@unnumberedsubsec Example
@smallexample Program TestAbs;
Var i1: Complex;
begin writeln ( abs ( 42 ) ); (* 42 *); writeln ( abs ( -42 ) ); (* 42 *); writeln ( abs ( -12.1 : 0 : 1 ) ); (* 12.1 *); i1:= cmplx ( 1, 1 ); (* 1 + i *) writeln ( abs ( i1 ) : 0 : 10 ); (* yields 1.4142135624, i.e. sqrt ( 2 ) *) end. @end smallexample
@unnumberedsubsec See also
@ref{sqr}.
@c ----------------------------------------------------------------------------
If you follow-up to this mail and modify the section, please include a complete copy without leading "> " or such in order to make it easier for me to integrate the modified copy into `reference.texi'.
Peter
PS: I just was pointed to some errors in the above, so you can expect my own follow-up to this in a few minutes. :-)
Hi again!
I (Peter Gerwinski) wrote:
This is an example entry for how I think our joined effort to complete the GPC reference could work. The section I am posting is already in existence (`abs'):
[...]
@unnumberedsubsec Description
Returns the absolute value of the argument:
@smallexample Function abs ( x: @var{some type} ): @var{some type};
begin (* abs *) if x < 0 then abs:= -x else abs:= x; end (* abs *); @end smallexample
Whoever wrote this ;-) forgot to think about complex values. A suggested correction follows below.
begin writeln ( abs ( 42 ) ); (* 42 *); writeln ( abs ( -42 ) ); (* 42 *); writeln ( abs ( -12.1 : 0 : 1 ) ); (* 12.1 *); i1:= cmplx ( 1, 1 ); (* 1 + i *) writeln ( abs ( i1 ) : 0 : 10 ); (* yields 1.4142135624, i.e. sqrt ( 2 ) *) end.
Maybe the comments should be in one column?
@c ----------------------------------------------------------------------------
@node abs @unnumberedsec abs @cindex abs
@unnumberedsubsec Syntax
@smallexample Function abs ( i: @var{integer type} ): @var{integer type}; @end smallexample or @smallexample Function abs ( x: @var{real type} ): @var{real type}; @end smallexample or @smallexample Function abs ( z: @var{complex type} ): @var{real type}; @end smallexample
@unnumberedsubsec Description
Returns the absolute value of the argument. For integer or real values of @samp{x}, the definition is
@smallexample Function abs ( x: @var{integer or real type} ): @var{integer or real type};
begin (* abs *) if x < 0 then abs:= -x else abs:= x; end (* abs *); @end smallexample
whereas for complex values it is
@smallexample Function abs ( x: Complex ): Complex;
begin (* abs *) abs:= sqrt ( x * conjugate ( x ) ); end (* abs *); @end smallexample
@unnumberedsubsec Standards
The function @samp{abs} is defined in ISO-7185 Standard Pascal; its application to complex values is defined in ISO-10206 Extended Pascal.
@unnumberedsubsec Example
@smallexample Program TestAbs;
Var i1: Complex;
begin writeln ( abs ( 42 ) ); (* 42 *); writeln ( abs ( -42 ) ); (* 42 *); writeln ( abs ( -12.1 : 0 : 1 ) ); (* 12.1 *); i1:= cmplx ( 1, 1 ); (* 1 + i *) writeln ( abs ( i1 ) : 0 : 3 ); (* 1.414, i.e. sqrt ( 2 ) *) end. @end smallexample
@unnumberedsubsec See also
@ref{sqr}.
@c ----------------------------------------------------------------------------
If you follow-up to this mail and modify the section, please include a complete copy without leading "> " or such in order to make it easier for me to integrate the modified copy into `reference.texi'.
I did so. ;-)
Okay - now it's your turn! (-:
Peter
According to Maurice Lombardi:
writeln ( abs ( -12.1 : 0 : 1 ) ); (* 12.1 *);
^^^^^^^^^^^ I think, something is goin wrong...
No no, at least in BP, the actual length is adjusted upwards to contain what needs to be written if the specified length is too short. [...]
No, that was not the issue: Carefully watch the nesting of the parentheses ... ;-)
Peter
Sven Hilscher a écrit:
writeln ( abs ( -12.1 : 0 : 1 ) ); (* 12.1 *);
^^^^^^^^^^^ I think, something is goin wrong...
No no, at least in BP, the actual length is adjusted upwards to contain what needs to be written if the specified length is too short. So with a specified length of 0 it adjusts in any case to the minimum length necessary to accomodate the number with the specified number of decimals. Bizarre but very handy in fact.