Hi All,
Could someone pls. help me with this: I would like to create own numeric type which consists for example only from these numbers "0,1,3,6,8,9".
However I do not want to have 2,4,5,7 there.
Thanks Peter
The point of having a numerical type is to have the ability to perform mathematical operations, but in case of a restricted set of numbers most of the time you'll be getting answers outside of the set, so you still need to perform checks afterwards. So either you just use the regular numbers and pretend all other don't exist, while validating what you have after each operation, or you use an enum and implement the required operations by hand.
Can't imagine any use-case at a go, though.
I do not really need "names". Of course I can get num value by ord() function but it is not appropriate. There is no arithmetic just small set of numbers. I checked some go-lang implementation and they use uint8 so it seems I use it also for NIM implementation.
There are many ways to do it. Perhaps something like:
# a data type called Example
type
ExampleDigits = enum
ed0 = 0,
ed1 = 1,
ed2 = 3,
ed6 = 6,
ed8 = 8,
ed9 = 9
type
Example = object
characteristic = seq[MyDigits]
mantissa = seq[MyDigits]
proc newExample(string): Example =
# do stuff here
proc toFloat(Example): float =
# do stuff
assert newExample("812.6").toFloat == 322.3 # or whatever 812.6 should equal :)