add comments to smalltalk impl

This commit is contained in:
jacekpoz 2024-04-12 14:10:04 +02:00
parent 4ed9cdf46a
commit 1ceca09860
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -23,12 +23,14 @@ Object subclass: GF [
ifTrue: [Error signal: 'both arguments must have the same characteristic']
]
"throws Error on different characteristics"
+ rhs [
self verifyCharacteristics: rhs.
^GF create: characteristic
withValue: ((value + rhs value) \\ characteristic)
]
"throws Error on different characteristics"
- rhs [
self verifyCharacteristics: rhs.
"^GF create: characteristic
@ -46,12 +48,15 @@ Object subclass: GF [
].
]
"throws Error on different characteristics"
* rhs [
self verifyCharacteristics: rhs.
^GF create: characteristic
withValue: ((value * rhs value) \\ characteristic)
]
"throws ZeroDivide on division by 0"
"throws Error on different characteristics"
/ rhs [
| inverse |
self verifyCharacteristics: rhs.
@ -67,44 +72,53 @@ Object subclass: GF [
withValue: ((value * inverse) \\ characteristic)
]
"throws Error on different characteristics"
= rhs [
self verifyCharacteristics: rhs.
^value = rhs value
]
"throws Error on different characteristics"
~= rhs [
self verifyCharacteristics: rhs.
^value ~= rhs value
]
"throws Error on different characteristics"
> rhs [
self verifyCharacteristics: rhs.
^value > rhs value
]
"throws Error on different characteristics"
< rhs [
self verifyCharacteristics: rhs.
^value < rhs value
]
"throws Error on different characteristics"
>= rhs [
self verifyCharacteristics: rhs.
^value >= rhs value
]
"throws Error on different characteristics"
<= rhs [
self verifyCharacteristics: rhs.
^value <= rhs value
]
"returns the characteristic of `self`"
characteristic [
^characteristic
]
"returns the value of `self`"
value [
^value
]
"prints `self` in a pretty format"
displayOn: stream [
'GF<' displayOn: stream.
characteristic displayOn: stream.