protected static Ptg calcNormdist( Ptg[] operands )
	{
		if( operands.length < 4 )
		{
			return new PtgErr( PtgErr.ERROR_VALUE );
		}
		try
		{
			//If mean or standard_dev is nonnumeric, NORMDIST returns the #VALUE! error value.
			double x = operands[0].getDoubleVal();
			double mean = operands[1].getDoubleVal();
			// if standard_dev ≤ 0, NORMDIST returns the #NUM! error value.
			double stddev = operands[2].getDoubleVal();
			if( stddev <= 0 )
			{
				return new PtgErr( PtgErr.ERROR_NUM );
			}
			boolean cumulative = PtgCalculator.getBooleanValue( operands[3] );
			// If mean = 0, standard_dev = 1, and cumulative = TRUE, NORMDIST returns the standard normal distribution, NORMSDIST.
			if( (mean == 0) && (stddev == 1.0) && cumulative )
			{
				return calcNormsdist( operands );
			}

			if( !cumulative )
			{    // return the probability mass function. *** definite excel algorithm
				double a = Math.sqrt( 2 * Math.PI * Math.pow( stddev, 2 ) );
				a = 1.0 / a;
				double exp = Math.pow( x - mean, 2 );
				exp = exp / (2 * Math.pow( stddev, 2 ));
				double b = Math.exp( -exp );
				return new PtgNumber( a * b );
			}
			// When cumulative = TRUE, the formula is the integral from negative infinity to x of the given formula.
			// = the cumulative distribution function
			Ptg[] o = { new PtgNumber( (x - mean) / (stddev * Math.sqrt( 2 )) ) };
			Ptg erf = EngineeringCalculator.calcErf( o );
			double cdf = 0.5 * (1 + erf.getDoubleVal());
			return new PtgNumber( cdf );
/*			 // try this:
			 Ptg[] o= { new PtgNumber((x-mean)/(stddev))};
			 return calcNormsdist(o);
	*/
		}
		catch( Exception e )
		{
			return new PtgErr( PtgErr.ERROR_VALUE );
		}
	}