Define a primitive data type: Difference between revisions
Content added Content deleted
Line 472: | Line 472: | ||
</lang> |
</lang> |
||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA |
ELENA 4.x: |
||
<lang elena>import extensions |
<lang elena>import extensions; |
||
sealed struct TinyInt |
sealed struct TinyInt : BaseNumber |
||
{ |
{ |
||
int value |
int value; |
||
int cast() = value; |
|||
constructor(int n) |
constructor(int n) |
||
{ |
|||
if |
if (n <= 1 || n >= 10) |
||
{ |
|||
InvalidArgumentException |
InvalidArgumentException.raise() |
||
}; |
|||
value := n |
value := n |
||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{ |
|||
value := s.toInt(); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{ |
|||
InvalidArgumentException.raise() |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
TinyInt subtract(TinyInt t) |
|||
= value |
= value - (cast int(t)); |
||
TinyInt multiply(TinyInt t) |
|||
= value |
= value * (cast int(t)); |
||
⚫ | |||
⚫ | |||
bool equal(TinyInt t) |
bool equal(TinyInt t) |
||
= value == |
= value == (cast int(t)); |
||
bool less(TinyInt t) |
bool less(TinyInt t) |
||
= value == |
= value == (cast int(t)); |
||
} |
} |
||
⚫ | |||
[ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
{ |
{ |
||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |