Overview

Namespaces

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

Classes

  • AbstractRationalType
  • GMPRationalType
  • RationalType
  • RationalTypeFactory
  • Overview
  • Namespace
  • Class
  • Tree

Class RationalTypeFactory

Static Factory for creating Rational types

chippyash\Type\AbstractTypeFactory
Extended by chippyash\Type\Number\Rational\RationalTypeFactory
Abstract
Namespace: chippyash\Type\Number\Rational
Located at Number/Rational/RationalTypeFactory.php
Methods summary
public static chippyash\Type\Number\Rational\RationalType|chippyash\Type\Number\Rational\GMPRationalType
# create( mixed $numerator, mixed $denominator = null )

Rational type factory Construct and return a rational. You can send in

  • a string conforming to 'n/d'
  • a float
  • two ints (numerator, denominator)

Rational type factory Construct and return a rational. You can send in

  • a string conforming to 'n/d'
  • a float
  • two ints (numerator, denominator)

Parameters

$numerator
$denominator

Returns

chippyash\Type\Number\Rational\RationalType|chippyash\Type\Number\Rational\GMPRationalType
\chippyash\Type\Number\Rational\RationalType|\chippyash\Type\Number\Rational\GMPRationalType

Throws

chippyash\Type\Exceptions\InvalidTypeException
InvalidTypeException
public static chippyash\Type\Number\Rational\RationalType|chippyash\Type\Number\Rational\GMPRationalType
# fromFloat( float|chippyash\Type\Number\FloatType $float, float|chippyash\Type\Number\FloatType $tolerance = null )

Create a rational number from a float or FloatType Use Continued Fractions method of determining the rational number

Create a rational number from a float or FloatType Use Continued Fractions method of determining the rational number

Parameters

$float
$tolerance
- Default is whatever is currently set but normally self::CF_DEFAULT_TOLERANCE

Returns

chippyash\Type\Number\Rational\RationalType|chippyash\Type\Number\Rational\GMPRationalType
\chippyash\Type\Number\Rational\RationalType|\chippyash\Type\Number\Rational\GMPRationalType

Throws

InvalidArgumentException
\InvalidArgumentException
public static chippyash\Type\Number\Rational\RationalType|chippyash\Type\Number\Rational\GMPRationalType
# fromString( string $string )

Create a rational number from a string in form 'n/d'

Create a rational number from a string in form 'n/d'

Thanks to Florian Wolters where I lifted this from and amended it

Parameters

$string

Returns

chippyash\Type\Number\Rational\RationalType|chippyash\Type\Number\Rational\GMPRationalType
\chippyash\Type\Number\Rational\RationalType|\chippyash\Type\Number\Rational\GMPRationalType

Throws

InvalidArgumentException
\InvalidArgumentException

Link

http://github.com/FlorianWolters/PHP-Component-Number-Fraction
public static
# setDefaultFromFloatTolerance( integer $tolerance )

Set the default tolerance for all fromFloat() operations N.B. This sets a static so only needs to be done once

Set the default tolerance for all fromFloat() operations N.B. This sets a static so only needs to be done once

Parameters

$tolerance
Methods inherited from chippyash\Type\AbstractTypeFactory
setNumberType()
Constants summary
float CF_DEFAULT_TOLERANCE

default error tolerance for fromFloat()

default error tolerance for fromFloat()

#1.e-15
Constants inherited from chippyash\Type\AbstractTypeFactory
TYPE_DEFAULT, TYPE_GMP, TYPE_NATIVE
Chippyash Strong Types API documentation generated by ApiGen 2.8.0