Define a primitive data type: Difference between revisions
Content added Content deleted
(Changed low bound to 1 to conform to the task requirement.) |
|||
Line 541: | Line 541: | ||
Integer => x, |
Integer => x, |
||
TinyInt => x.toInteger(), |
TinyInt => x.toInteger(), |
||
_ => throw "Type \"\(x.getType():name)\" is not supported by this operation." |
_ => throw "Type \"\(x.getType()::name)\" is not supported by this operation." |
||
} |
} |
||
} |
} |
||
Line 553: | Line 553: | ||
} |
} |
||
func TinyInt.TinyInt(i) cons { |
|||
boundsCheck(Integer(i)) |
|||
} |
} |
||
func TinyInt.toString() { |
func TinyInt.toString() decons { |
||
this.toString() |
|||
} |
} |
||
func TinyInt.toInteger() { |
func TinyInt.toInteger() decons { |
||
this |
|||
} |
} |
||
func TinyInt + (other) { |
func TinyInt + (other) decons { |
||
let z = this + getInteger(other) |
|||
TinyInt(z) |
TinyInt(z) |
||
} |
} |
||
func TinyInt * (other) { |
func TinyInt * (other) decons { |
||
let z = this * getInteger(other) |
|||
TinyInt(z) |
TinyInt(z) |
||
} |
} |
||
func TinyInt - (other) { |
func TinyInt - (other) decons { |
||
let z = this - getInteger(other) |
|||
TinyInt(z) |
TinyInt(z) |
||
} |
} |
||
func TinyInt / (other) { |
func TinyInt / (other) decons { |
||
let z = this / getInteger(other) |
|||
TinyInt(z) |
TinyInt(z) |
||
}</lang> |
}</lang> |