NCL Home > Documentation > Functions > General applied math

get_pi

Return pi as a type float or double.

Available in version 6.4.0 and later.

Prototype

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

	function get_pi (
		val       
	)

	return_val [scalar] :  float or double

Arguments

val

If val is type numeric, and val is type "double", the returned pi will be type double; otherwise it will be type float.

If val is type string, and val="double" or val="d", the returned pi will be type double; otherwise it will be type float.

If val is any other type, the returned pi will be type float.

It is recommended that the value returned be the same numeric type as the variable(s) with which it will be used.

Return value

The returned scalar pi will be type double or float.

Description

pi is a mathematical constant which is the ratio of a circle's circumference to its diameter.

It is recommended that the value returned by get_pi (get_d2r and get_r2d) be the same numeric type as the variable(s) with which it will be used.

See Also

get_d2r, get_r2d

Examples

Example 1: Of course, the name to the left of the assignment statement can be any valid name.


  PI  = get_pi("double")   ; type double; 3.141592653589793
  PI  = get_pi("float" )   ; type float ; 3.141593

  pi  = get_pi("d")        ; type double
  pi  = get_pi("f")        ; type float

  pi  = get_pi(1d0)        ; type double
  pi  = get_pi(1.0)        ; type float
  pi  = get_pi( 1 )        ; type float

  xf   = 2.412        
  xd   = 2.412d0           
  xi   = 100      

  pi  = get_pi(xd)         ; type double
  pi  = get_pi(xf)         ; type float
  pi  = get_pi(xi)         ; type float