First of all, there is no need to convert literals. x = 1.0
is the same as x = scalar(1.0)
assuming x already has the type scalar.
In Go, there is no such thing as a user defined type alias. In Go, byte and uint8 (which are builtin types) are considered aliases of each other. They are two names for the same type. Float64 and scalar are not the same type. Values of float64 and scalar need to be converted between each other using something like s = scalar(f)
while byte and uint8 do not.
However, such conversions have no overhead. The types are enforced at compile time for code correctness but does not affect performance during execution. Execution is only affected if you do type assertions or use reflection. However, these differences affect logic, not performance.
Can I use this when performance is absolutely critical?
Yes