object PosDouble
The companion object for PosDouble
that offers
factory methods that produce PosDouble
s,
implicit widening conversions from PosDouble
to
other numeric types, and maximum and minimum constant values
for PosDouble
.
- Source
- PosDouble.scala
- Alphabetic
- By Inheritance
- PosDouble
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
val
MaxValue: PosDouble
The largest value representable as a positive
Double
, which isPosDouble(1.7976931348623157E308)
.The largest value representable as a positive
Double
, which isPosDouble(1.7976931348623157E308)
. - final val MinPositiveValue: PosDouble
-
final
val
MinValue: PosDouble
The smallest value representable as a positive
Double
, which isPosDouble(4.9E-324)
.The smallest value representable as a positive
Double
, which isPosDouble(4.9E-324)
. -
final
val
PositiveInfinity: PosDouble
The positive infinity value, which is
PosDouble.ensuringValid(Double.PositiveInfinity)
.The positive infinity value, which is
PosDouble.ensuringValid(Double.PositiveInfinity)
. -
implicit macro
def
apply(value: Double): PosDouble
A factory method, implemented via a macro, that produces a
PosDouble
if passed a validDouble
literal, otherwise a compile time error.A factory method, implemented via a macro, that produces a
PosDouble
if passed a validDouble
literal, otherwise a compile time error.The macro that implements this method will inspect the specified
Double
expression at compile time. If the expression is a positiveDouble
literal, it will return aPosDouble
representing that value. Otherwise, the passedDouble
expression is either a literal that is not positive, or is not a literal, so this method will give a compiler error.This factory method differs from the
from
factory method in that this method is implemented via a macro that inspectsDouble
literals at compile time, whereasfrom
inspectsDouble
values at run time.- value
the
Double
literal expression to inspect at compile time, and if positive, to return wrapped in aPosDouble
at run time.- returns
the specified, valid
Double
literal value wrapped in aPosDouble
. (If the specified expression is not a validDouble
literal, the invocation of this method will not compile.)
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
ensuringValid(value: Double): PosDouble
A factory/assertion method that produces a
PosDouble
given a validDouble
value, or throwsAssertionError
, if given an invalidDouble
value.A factory/assertion method that produces a
PosDouble
given a validDouble
value, or throwsAssertionError
, if given an invalidDouble
value.This method will inspect the passed
Double
value and if it is a positiveDouble
, it will return aPosDouble
representing that value. Otherwise, the passedDouble
value is not positive, so this method will throwAssertionError
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsDouble
literals at compile time, whereasfrom
inspectsDouble
values at run time. It differs from a vanillaassert
orensuring
call in that you get something you didn't already have if the assertion succeeds: a type that promises aDouble
is positive.- value
the
Double
to inspect, and if positive, return wrapped in aPosDouble
.- returns
the specified
Double
value wrapped in aPosDouble
, if it is positive, else throwsAssertionError
.
- Exceptions thrown
AssertionError
if the passed value is not positive
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
from(value: Double): Option[PosDouble]
A factory method that produces an
Option[PosDouble]
given aDouble
value.A factory method that produces an
Option[PosDouble]
given aDouble
value.This method will inspect the passed
Double
value and if it is a positiveDouble
, it will return aPosDouble
representing that value, wrapped in aSome
. Otherwise, the passedDouble
value is not positive, so this method will returnNone
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsDouble
literals at compile time, whereasfrom
inspectsDouble
values at run time.- value
the
Double
to inspect, and if positive, return wrapped in aSome[PosDouble]
.- returns
the specified
Double
value wrapped in aSome[PosDouble]
, if it is PosDouble, elseNone
.
-
def
fromOrElse(value: Double, default: ⇒ PosDouble): PosDouble
A factory method that produces a
PosDouble
given aDouble
value and a defaultPosDouble
.A factory method that produces a
PosDouble
given aDouble
value and a defaultPosDouble
.This method will inspect the passed
Double
value and if it is a positiveDouble
, it will return aPosDouble
representing that value. Otherwise, the passedDouble
value is positive, so this method will return the passeddefault
value.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsDouble
literals at compile time, whereasfrom
inspectsDouble
values at run time.- value
the
Double
to inspect, and if positive, return.- default
the
PosDouble
to return if the passedDouble
value is not positive.- returns
the specified
Double
value wrapped in aPosDouble
, if it is positive, else thedefault
PosDouble
value.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
goodOrElse[B](value: Double)(f: (Double) ⇒ B): Or[PosDouble, B]
A factory/validation method that produces a
PosDouble
, wrapped in aGood
, given a validDouble
value, or if the givenDouble
is invalid, an error value of typeB
produced by passing the given invalidDouble
value to the given functionf
, wrapped in aBad
.A factory/validation method that produces a
PosDouble
, wrapped in aGood
, given a validDouble
value, or if the givenDouble
is invalid, an error value of typeB
produced by passing the given invalidDouble
value to the given functionf
, wrapped in aBad
.This method will inspect the passed
Double
value and if it is a positiveDouble
, it will return aPosDouble
representing that value, wrapped in aGood
. Otherwise, the passedDouble
value is not positive, so this method will return a result of typeB
obtained by passing the invalidDouble
value to the given functionf
, wrapped in aBad
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsDouble
literals at compile time, whereas this method inspectsDouble
values at run time.- value
the
Double
to inspect, and if positive, return wrapped in aGood(PosDouble)
.- returns
the specified
Double
value wrapped in aGood(PosDouble)
, if it is positive, else aBad(f(value))
.
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isValid(value: Double): Boolean
A predicate method that returns true if a given
Double
value is positive.A predicate method that returns true if a given
Double
value is positive.- value
the
Double
to inspect, and if positive, return true.- returns
true if the specified
Double
is positive, else false.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
implicit
val
ordering: Ordering[PosDouble]
Implicit Ordering instance.
-
def
passOrElse[E](value: Double)(f: (Double) ⇒ E): Validation[E]
A validation method that produces a
Pass
given a validDouble
value, or an error value of typeE
produced by passing the given invalidInt
value to the given functionf
, wrapped in aFail
.A validation method that produces a
Pass
given a validDouble
value, or an error value of typeE
produced by passing the given invalidInt
value to the given functionf
, wrapped in aFail
.This method will inspect the passed
Double
value and if it is a positiveDouble
, it will return aPass
. Otherwise, the passedDouble
value is positive, so this method will return a result of typeE
obtained by passing the invalidDouble
value to the given functionf
, wrapped in aFail
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsDouble
literals at compile time, whereas this method inspectsDouble
values at run time.- value
the
Int
to validate that it is positive.- returns
a
Pass
if the specifiedInt
value is positive, else aFail
containing an error value produced by passing the specifiedDouble
to the given functionf
.
-
def
rightOrElse[L](value: Double)(f: (Double) ⇒ L): Either[L, PosDouble]
A factory/validation method that produces a
PosDouble
, wrapped in aRight
, given a validDouble
value, or if the givenDouble
is invalid, an error value of typeL
produced by passing the given invalidDouble
value to the given functionf
, wrapped in aLeft
.A factory/validation method that produces a
PosDouble
, wrapped in aRight
, given a validDouble
value, or if the givenDouble
is invalid, an error value of typeL
produced by passing the given invalidDouble
value to the given functionf
, wrapped in aLeft
.This method will inspect the passed
Double
value and if it is a positiveDouble
, it will return aPosDouble
representing that value, wrapped in aRight
. Otherwise, the passedDouble
value is not positive, so this method will return a result of typeL
obtained by passing the invalidDouble
value to the given functionf
, wrapped in aLeft
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsDouble
literals at compile time, whereas this method inspectsDouble
values at run time.- value
the
Double
to inspect, and if positive, return wrapped in aRight(PosDouble)
.- returns
the specified
Double
value wrapped in aRight(PosDouble)
, if it is positive, else aLeft(f(value))
.
-
def
sumOf(first: PosDouble, second: PosZDouble, rest: PosZDouble*): PosDouble
Returns the
PosDouble
sum of the passedPosDouble
valuefirst
, thePosZDouble
valuesecond
, and thePosZDouble
values passed as varargsrest
.Returns the
PosDouble
sum of the passedPosDouble
valuefirst
, thePosZDouble
valuesecond
, and thePosZDouble
values passed as varargsrest
.This method will always succeed (not throw an exception) because adding a positive Double and one or more non-negative Doubles will always result in another positive Double value (though the result may be infinity).
This overloaded form of the
sumOf
method can sum more than two values, but unlike its two-arg sibling, will entail boxing. -
def
sumOf(x: PosDouble, y: PosZDouble): PosDouble
Returns the
PosDouble
sum of the passedPosDouble
valuex
andPosZDouble
valuey
.Returns the
PosDouble
sum of the passedPosDouble
valuex
andPosZDouble
valuey
.This method will always succeed (not throw an exception) because adding a positive Double and non-negative Double will always result in another positive Double value (though the result may be infinity).
This overloaded form of the method is used when there are just two arguments so that boxing is avoided. The overloaded
sumOf
that takes a varargs ofPosZDouble
starting at the third parameter can sum more than two values, but will entail boxing and may therefore be less efficient. -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
tryingValid(value: Double): Try[PosDouble]
A factory/validation method that produces a
PosDouble
, wrapped in aSuccess
, given a validFloat
value, or if the givenFloat
is invalid, anAssertionError
, wrapped in aFailure
.A factory/validation method that produces a
PosDouble
, wrapped in aSuccess
, given a validFloat
value, or if the givenFloat
is invalid, anAssertionError
, wrapped in aFailure
.Note: you should use this method only when you are convinced that it will always succeed, i.e., never throw an exception. It is good practice to add a comment near the invocation of this method indicating why you think it will always succeed to document your reasoning. If you are not sure an
ensuringValid
call will always succeed, you should use one of the other factory or validation methods provided on this object instead:isValid
,tryingValid
,passOrElse
,goodOrElse
, orrightOrElse
.This method will inspect the passed
Float
value and if it is a positiveFloat
, it will return aPosDouble
representing that value, wrapped in aSuccess
. Otherwise, the passedFloat
value is not positive, so this method will return anAssertionError
, wrapped in aFailure
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsFloat
literals at compile time, whereas this method inspectsFloat
values at run time.- value
the
Float
to inspect, and if positive, return wrapped in aSuccess(PosDouble)
.- returns
the specified
Float
value wrapped in aSuccess(PosDouble)
, if it is positive, else aFailure(AssertionError)
.
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
implicit
def
widenToDouble(pos: PosDouble): Double
Implicit widening conversion from
PosDouble
toDouble
.Implicit widening conversion from
PosDouble
toDouble
.- pos
the
PosDouble
to widen- returns
the
Double
value underlying the specifiedPosDouble
-
implicit
def
widenToNonZeroDouble(pos: PosDouble): NonZeroDouble
Implicit widening conversion from
PosDouble
toNonZeroDouble
.Implicit widening conversion from
PosDouble
toNonZeroDouble
.- pos
the
PosDouble
to widen- returns
the
Double
value underlying the specifiedPosDouble
, widened toDouble
and wrapped in aNonZeroDouble
.
-
implicit
def
widenToPosZDouble(pos: PosDouble): PosZDouble
Implicit widening conversion from
PosDouble
toPosZDouble
.Implicit widening conversion from
PosDouble
toPosZDouble
.- pos
the
PosDouble
to widen- returns
the
Double
value underlying the specifiedPosDouble
, widened toDouble
and wrapped in aPosZDouble
.