Pi Function(Borland Pascal)

Computing|Pascal

Pi Function(Borland Pascal)

By Jeff Duntemann
A real number function included as part of the Borland Pascal RTL, returning the mathematical value of Pi to whatever accuracy the assigned-to data type can express. The Pi function takes no parameters and is illegal to use with integer types.

Borland's Pascal compilers include as part of the runtime library a standard function Pi that returns the value of pi to as many significant figures as the variable to which it returns the value may express. The value returned is a real number type and so may not be assigned to any integer type, but (as with any real number value) may be assigned to Borland proprietary type Real and the IEEE math coprocessor types Single, Double, Extended and Comp.

You should keep in mind that differences in precision in the type receiving a value from Pi will affect the exact decimal values returned, although for all but the most exacting requirements these differences can be ignored.

To illustrate, the following code displays the actual values returned by function Pi to the various real number types:


VAR

  RS : Single;

  RR : Real;

  RD : Double;

  RE : Extended;

  RC : Comp;



  RS := Pi; RR := Pi; RD := Pi; RE := Pi; RC := Pi;

  Writeln('Type Single:   ',RS:4:25);

  Writeln('Type Real:     ',RR:4:25);

  Writeln('Type Double:   ',RD:4:25);

  Writeln('Type Extended: ',RE:4:25);

  Writeln('Type Comp:     ',RC:4:25);

And here is the output you'll see:


Type Single:   3.141592741012573240

Type Real:     3.141592653588304530

Type Double:   3.141592653589793120

Type Extended: 3.141592653589793240

Type Comp:     3.000000000000000000

Note from the above display that type Comp can accept a value from Pi without triggering an error but will not store the fractional part!