How to define new primitive data type and its behavior in Scala -


is there way create new data type define number of bits , arithmetic rules in scala? have program uses 32 bit floats trying study how affect results.

i want rewrite program addition , multiplication on fixed point (d.f) numbers , return fixed point numbers of same precision (d.f , not d1+d2.f1+f2). furthermore, want have saturation when there overflow, result sticks maxed value rather wrapping around. want truncate bits if there underflow.

from understand, 8 bit number short, , decimal numbers floats , doubles. can somehow define data type in scala, or way regular float arithmetic , round nearest number can represented desired type?

thanks

you limited types jvm provides , supports unless go , hack jvm, or compile scala native code custom compiler settings.

more reasonable approach achieve store numbers fractions. there libraries spire let that. spire can chose double or rational speed/precision trade off.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -