Number protocol

From Erights

Jump to: navigation, search

For some type T which is like a number, these are the conventional messages to implement.

This protocol is implemented by Integer and Float64.

XXX This list is not complete, not properly documented, and not discussed.

XXX Consider whether this page could be turned into a template which generates tests of the number protocol for specific number types.

XXX This documentation needs to acknowledge behavior with respect to numbers of other types; e.g. where this is an integer and an argument is a float. Just saying type T doesn't acknowlege that the result might be of another type.

Contents

Protocol

add/1

Signature: add(other :T) :T

Sugar expansion of +. XXX write documentation

subtract/1

Signature: subtract(other :T) :T

Sugar expansion of -. XXX write documentation

multiply/1

Signature: multiply(other :T) :T

Sugar expansion of *. XXX write documentation

floorDivide/1

Signature: floorDivide(other :T) :T

Sugar expansion of //. XXX write documentation

approxDivide/1

Signature: approxDivide(other :T) :T

Sugar expansion of /. XXX write documentation

remainder/1

Signature: remainder(other :T) :T

Sugar expansion of %. XXX write documentation

mod/1

Signature: mod(other :T) :T

Sugar expansion of %%. XXX write documentation

pow/1

Signature: pow(other :T) :T

Sugar expansion of **. XXX write documentation

modPow/2

Signature: modPow(exponent :T, modulus :T) :T

Sugar expansion of this ** exponent %% modulus.

Equivalent to this.pow(exponent).mod(modulus).

It is expected that when this is an integer, modulus is a nonzero integer and exponent is a positive integer, this operation will be implemented efficiently.

XXX In E-on-Java, a negative modulus will throw an exception rather than computing the compositional answer. The above spec I just wrote contradicts this. Resolve. --Kevin Reid 23:51, 30 July 2009 (CDT)

negate/0

Signature: negate() :T

Sugar expansion of -. Return the additive inverse of the receiver.

abs/0

Signature: abs() :T

Return the absolute value of the receiver.

max/1

Signature: max(other :T) :T

Compare the recipient to other, and return whichever is greater.

min/1

Signature: min(other :T) :T

Compare the recipient to other, and return whichever is lesser.

This page is a stub; it should be expanded with more information. If doing so, check the original E web site and the mailing list archives for content which could be moved into this page.
Personal tools
more tools