NumberIsFractional

com.phasmidsoftware.number.core.numerical.Number.NumberIsFractional
See theNumberIsFractional companion trait

Provides an implicit object for handling operations on Number with fractional, numeric, and ordering capabilities.

This implicit object combines the functionality of NumberIsFractional, NumberIsNumeric, and NumberIsOrdering, enabling division operations along with general numeric and ordering functionalities for the Number type.

Attributes

Companion
trait
Graph
Supertypes
trait Fractional[Number]
trait Numeric[Number]
trait Ordering[Number]
trait PartialOrdering[Number]
trait Equiv[Number]
trait Serializable
trait Comparator[Number]
class Object
trait Matchable
class Any
Show all
Self type

Members list

Type members

Inherited classlikes

class FractionalOps(lhs: Fractional.this.T) extends NumericOps

Attributes

Inherited from:
Fractional
Supertypes
class Fractional.this.NumericOps
class Object
trait Matchable
class Any
class NumericOps(lhs: Numeric.this.T)

Attributes

Inherited from:
Numeric
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Fractional.this.FractionalOps
class OrderingOps(lhs: Ordering.this.T)

This inner class defines comparison operators available for T.

This inner class defines comparison operators available for T.

It can't extend AnyVal because it is not a top-level class or a member of a statically accessible object.

Value parameters

lhs

the left-hand side value for infix comparison operations

Attributes

Inherited from:
Ordering
Supertypes
class Object
trait Matchable
class Any

Value members

Inherited methods

def abs(x: Number): Number

Attributes

Inherited from:
Numeric
def compare(x: Number, y: Number): Int

When we do a compare on NatLog numbers, they are in the same order as PureNumber numbers (i.e. monotonically increasing). It's not necessary to convert exact numbers to fuzzy numbers for this purpose, we simply pretend that the NatLog numbers are PureNumber numbers.

When we do a compare on NatLog numbers, they are in the same order as PureNumber numbers (i.e. monotonically increasing). It's not necessary to convert exact numbers to fuzzy numbers for this purpose, we simply pretend that the NatLog numbers are PureNumber numbers.

Value parameters

x

the first Number.

y

the second Number.

Attributes

Returns

an Int representing the order.

Inherited from:
NumberIsOrdering
def div(x: Number, y: Number): Number

Divides one Number by another Number.

Divides one Number by another Number.

Value parameters

x

the numerator, represented as a Number

y

the denominator, represented as a Number, which must be invertible

Attributes

Returns

the result of dividing x by y, represented as a Number

Inherited from:
NumberIsFractional
override def equiv(x: Number, y: Number): Boolean

Returns true if x == y in the ordering.

Returns true if x == y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering -> Equiv
Inherited from:
Ordering
def fromInt(x: Int): Number

Creates a Number instance from the given integer value.

Creates a Number instance from the given integer value.

Value parameters

x

the integer value to be converted to a Number

Attributes

Returns

a Number representing the given integer value

Inherited from:
NumberIsNumeric
override def gt(x: Number, y: Number): Boolean

Returns true if x > y in the ordering.

Returns true if x > y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
override def gteq(x: Number, y: Number): Boolean

Returns true if x >= y in the ordering.

Returns true if x >= y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def isReverseOf(other: Ordering[_]): Boolean

Returns whether or not the other ordering is the opposite ordering of this one.

Returns whether or not the other ordering is the opposite ordering of this one.

Equivalent to other == this.reverse.

Implementations should only override this method if they are overriding reverse as well.

Value parameters

other

the ordering to check

Attributes

Returns

true if other is the reverse of this ordering, false otherwise

Inherited from:
Ordering
override def lt(x: Number, y: Number): Boolean

Returns true if x < y in the ordering.

Returns true if x < y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
override def lteq(x: Number, y: Number): Boolean

Returns true if x <= y in the ordering.

Returns true if x <= y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def max[U <: Number](x: U, y: U): U

Returns x if x >= y, otherwise y.

Returns x if x >= y, otherwise y.

Type parameters

U

a subtype of T, used to preserve the specific type in the return value

Value parameters

x

the first candidate value

y

the second candidate value

Attributes

Inherited from:
Ordering
def min[U <: Number](x: U, y: U): U

Returns x if x <= y, otherwise y.

Returns x if x <= y, otherwise y.

Type parameters

U

a subtype of T, used to preserve the specific type in the return value

Value parameters

x

the first candidate value

y

the second candidate value

Attributes

Inherited from:
Ordering
def minus(x: Number, y: Number): Number

Subtracts the second number from the first number.

Subtracts the second number from the first number.

Value parameters

x

the number from which the second number will be subtracted

y

the number to be subtracted from the first number

Attributes

Returns

the result of subtracting y from x

Inherited from:
NumberIsNumeric
def negate(x: Number): Number

Negates the given Number instance.

Negates the given Number instance.

Value parameters

x

the Number to be negated

Attributes

Returns

a new Number that is the negation of the input Number

Inherited from:
NumberIsNumeric
def on[U](f: U => Number): Ordering[U]

Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:

Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:

def compare[U, T: Ordering](x: U, y: U, f: U => T) = Ordering[T].compare(f(x), f(y))

Type parameters

U

the type of the values to be ordered

Value parameters

f

the function to extract a T value from a U value

Attributes

Returns

an Ordering[U] that orders values by applying f and comparing the results using this ordering

Inherited from:
Ordering
def one: Number

Attributes

Inherited from:
Numeric
def orElse(other: Ordering[Number]): Ordering[Number]

Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.

Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.

Value parameters

other

an Ordering to use if this Ordering returns zero

Attributes

Returns

an Ordering[T] that uses this ordering first, falling back to other when values are equal

Example
case class Pair(a: Int, b: Int)
val pairOrdering = Ordering.by[Pair, Int](_.a)
                          .orElse(Ordering.by[Pair, Int](_.b))
Inherited from:
Ordering
def orElseBy[S](f: Number => S)(implicit ord: Ordering[S]): Ordering[Number]

Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:

Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:

def compare[T, S: Ordering](x: T, y: T, f: T => S) = Ordering[S].compare(f(x), f(y))

This function is equivalent to passing the result of Ordering.by(f) to orElse.

Type parameters

S

the type returned by the extraction function f

Value parameters

f

the function to extract a comparison key from a T value

ord

the implicit ordering for the extracted key type S

Attributes

Returns

an Ordering[T] that uses this ordering first, falling back to comparing by f when values are equal

Example
case class Pair(a: Int, b: Int)
val pairOrdering = Ordering.by[Pair, Int](_.a)
                          .orElseBy[Int](_.b)
Inherited from:
Ordering
def parseString(str: String): Option[Number]

Parses the given string representation of a number and attempts to convert it into an Option of Number.

Parses the given string representation of a number and attempts to convert it into an Option of Number.

Value parameters

str

the string to be parsed as a potential representation of a Number

Attributes

Returns

an Option containing the parsed Number if conversion is successful, or None if parsing fails

Inherited from:
NumberIsNumeric
def plus(x: Number, y: Number): Number

Adds two Number instances and returns their sum.

Adds two Number instances and returns their sum.

Value parameters

x

the first Number to be added

y

the second Number to be added

Attributes

Returns

the result of adding x and y as a Number

Inherited from:
NumberIsNumeric
override def reverse: Ordering[Number]

Returns the opposite ordering of this one.

Returns the opposite ordering of this one.

Implementations overriding this method MUST override isReverseOf as well if they change the behavior at all (for example, caching does not require overriding it).

Attributes

Returns

an Ordering[T] that compares elements in the reverse order of this ordering

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def reversed(): Comparator[Number]

Attributes

Inherited from:
Comparator
def sign(x: Number): Number

Attributes

Inherited from:
Numeric
def thenComparing[U <: Comparable[_ >: U <: <FromJavaObject>]](x$0: Function[_ >: Number <: <FromJavaObject>, _ <: U]): Comparator[Number]

Attributes

Inherited from:
Comparator
def thenComparing[U <: <FromJavaObject>](x$0: Function[_ >: Number <: <FromJavaObject>, _ <: U], x$1: Comparator[_ >: U <: <FromJavaObject>]): Comparator[Number]

Attributes

Inherited from:
Comparator
def thenComparing(x$0: Comparator[_ >: Number <: <FromJavaObject>]): Comparator[Number]

Attributes

Inherited from:
Comparator
def thenComparingDouble(x$0: ToDoubleFunction[_ >: Number <: <FromJavaObject>]): Comparator[Number]

Attributes

Inherited from:
Comparator
def thenComparingInt(x$0: ToIntFunction[_ >: Number <: <FromJavaObject>]): Comparator[Number]

Attributes

Inherited from:
Comparator
def thenComparingLong(x$0: ToLongFunction[_ >: Number <: <FromJavaObject>]): Comparator[Number]

Attributes

Inherited from:
Comparator
def times(x: Number, y: Number): Number

Multiplies two Number values and returns the result.

Multiplies two Number values and returns the result.

Value parameters

x

the first Number operand

y

the second Number operand

Attributes

Returns

the product of the two given Number values

Inherited from:
NumberIsNumeric
def toDouble(x: Number): Double

Converts the given Number instance to a Double.

Converts the given Number instance to a Double.

Value parameters

x

the Number instance to be converted to a Double

Attributes

Returns

the Double representation of the input Number

Note

Throws CoreException if the Number instance cannot be converted to a Double

Inherited from:
NumberIsNumeric
def toFloat(x: Number): Float

Converts a given Number to a Float value by first converting it to a Double and then to a Float.

Converts a given Number to a Float value by first converting it to a Double and then to a Float.

Value parameters

x

the Number to be converted to a Float

Attributes

Returns

the Float representation of the given Number

Inherited from:
NumberIsNumeric
def toInt(x: Number): Int

Converts a given Number instance to an Int.

Converts a given Number instance to an Int.

Value parameters

x

the Number to be converted to an Int

Attributes

Returns

the integer representation of the given Number

Inherited from:
NumberIsNumeric
def toLong(x: Number): Long

Converts the given Number instance to a Long representation. If the number is a GeneralNumber and contains a rational value, the rational is converted to a Long. If the rational is absent but a double value is present, it rounds the double to the closest Long. Throws an exception if neither a rational nor a valid double representation can be derived.

Converts the given Number instance to a Long representation. If the number is a GeneralNumber and contains a rational value, the rational is converted to a Long. If the rational is absent but a double value is present, it rounds the double to the closest Long. Throws an exception if neither a rational nor a valid double representation can be derived.

Value parameters

x

the number to be converted to a Long

Attributes

Returns

the Long representation of the given number

Note

Throws CoreException if the conversion is not possible

Inherited from:
NumberIsNumeric
def tryCompare(x: Number, y: Number): Some[Int]

Returns whether a comparison between x and y is defined, and if so the result of compare(x, y).

Returns whether a comparison between x and y is defined, and if so the result of compare(x, y).

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Inherited from:
Ordering
def zero: Number

Attributes

Inherited from:
Numeric

Deprecated and Inherited methods

def signum(x: Number): Int

Attributes

Deprecated
[Since version 2.13.0] use `sign` method instead
Inherited from:
Numeric

Implicits

Inherited implicits

implicit override def mkNumericOps(lhs: Number): FractionalOps

Attributes

Definition Classes
Fractional -> Numeric
Inherited from:
Fractional
implicit def mkOrderingOps(lhs: Number): OrderingOps

This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.

This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.

Value parameters

lhs

the value to enrich with ordering operators

Attributes

Inherited from:
Ordering