Overview

Namespaces

  • chippyash
    • Type
      • Exceptions
      • Interfaces
      • Number
        • Complex
        • Rational
      • String

Classes

  • AbstractComplexType
  • ComplexType
  • ComplexTypeFactory
  • GMPComplexType
  • Overview
  • Namespace
  • Class
  • Tree

Class ComplexTypeFactory

Static Factory for creating complex types

A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and i is the imaginary unit, which satisfies the equation i² = −1

chippyash\Type\AbstractTypeFactory
Extended by chippyash\Type\Number\Complex\ComplexTypeFactory
Abstract
Namespace: chippyash\Type\Number\Complex
Located at Number/Complex/ComplexTypeFactory.php
Methods summary
public static chippyash\Type\Number\Complex\ComplexType
# create( string|float|integer|chippyash\Type\Number\FloatType|chippyash\Type\Number\IntType $realPart, float|integer|chippyash\Type\Number\FloatType|chippyash\Type\Number\IntType $imaginaryPart = null )

Complex type factory

Complex type factory

Construct and return a complex number. You can send in

  • a string conforming to 'a+bi', 'a-bi', '-a+bi', '-a-bi' where a & b

are integer or float numbers e.g. '-12+0.67i'

  • mixture of numeric (int,float,'1234' etc), IntType and FloatType corresponding to a & b

Parameters

$realPart
$imaginaryPart

Returns

chippyash\Type\Number\Complex\ComplexType
\chippyash\Type\Number\Complex\ComplexType

Throws

InvalidArgumentException
\InvalidArgumentException
public static chippyash\Type\Number\Complex\ComplexType
# fromString( string $string )

Create a complex number from a string in form '[+,-]<num>(+,-)<num>i' The trailing 'i' character is required No spaces are allowed in the string

Create a complex number from a string in form '[+,-]<num>(+,-)<num>i' The trailing 'i' character is required No spaces are allowed in the string

Parameters

$string

Returns

chippyash\Type\Number\Complex\ComplexType
\chippyash\Type\Number\Complex\ComplexType

Throws

InvalidArgumentException
\InvalidArgumentException
public static chippyash\Type\Number\Complex\ComplexType
# fromPolar( chippyash\Type\Number\Rational\AbstractRationalType $radius, chippyash\Type\Number\Rational\AbstractRationalType $theta )

Create complex type from polar co-ordinates

Create complex type from polar co-ordinates

Be aware that you may lose a bit of precision e.g. $c = ComplexTypeFactory::create('2/7+3/4i'); $c2 = ComplexTypeFactory::fromPolar($c->radius(), $c->theta()); returns 132664833738225/464326918083788+3382204885901775/4509606514535696i which is ~0.2857142857142854066 + ~0.75000000000000066525i whereas the original is ~0.28571428571428571429 + 0.75i

formula for conversion is z = r(cos(theta) + i.sin(theta))

Parameters

$radius
$theta
angle expressed in radians

Returns

chippyash\Type\Number\Complex\ComplexType
\chippyash\Type\Number\Complex\ComplexType
public static chippyash\Type\Number\Complex\ComplexType
# fromNativePolar( chippyash\Type\Number\Rational\RationalType $radius, chippyash\Type\Number\Rational\RationalType $theta )

Create complex type from polar co-ordinates - Native version

Create complex type from polar co-ordinates - Native version

z = radius x (cos(theta) + i.sin(theta)) real = radius x cos(theta) imag = radius x sin(theta)

Parameters

$radius
$theta
angle expressed in radians

Returns

chippyash\Type\Number\Complex\ComplexType
\chippyash\Type\Number\Complex\ComplexType
public static chippyash\Type\Number\Complex\GMPComplexType
# fromGmpPolar( chippyash\Type\Number\Rational\GMPRationalType $radius, chippyash\Type\Number\Rational\GMPRationalType $theta )

Create complex type from polar co-ordinates - GMP version

Create complex type from polar co-ordinates - GMP version

Parameters

$radius
$theta
angle expressed in radians

Returns

chippyash\Type\Number\Complex\GMPComplexType
\chippyash\Type\Number\Complex\GMPComplexType
Methods inherited from chippyash\Type\AbstractTypeFactory
setNumberType()
Constants inherited from chippyash\Type\AbstractTypeFactory
TYPE_DEFAULT, TYPE_GMP, TYPE_NATIVE
Chippyash Strong Types API documentation generated by ApiGen 2.8.0