I think you misunderstood the question or it wasn’t clear. The struct can only contain a single int64 - so you cannot add another value to hold the number of decimal places. 

The idea is to track the number of decimal places via the type (or method on the type) so the compiler knows it while generating the code. 

It’s clear in the C++ code. 

On Oct 15, 2024, at 9:17 PM, Cleberson Pedreira Pauluci <pauluci.cleber...@gmail.com> wrote:

Hi.

Maybe you can use encapsulation instead of standalone function and generics.
Encapsulation is a fundamental principle in software engineering. It controls which parts of a package are visible from the outside and which are not.
It hides implementation details, allowing changes that do not affect dependent code.

Check it out: https://go.dev/play/p/xqwMPgB0IND

I really hope I can help you.

Cheers.
Cleberson


Em terça-feira, 15 de outubro de 2024 às 21:01:42 UTC-3, Robert Engels escreveu:
Hi,


I could make the type and interface and add a method for ‘decimal places’, but I would like all of the constants to be resolved at compile time.

Also, if I make it an interface, it is far less efficient than passing a single int64 with generics and letting the compiler figure it out.

I know constexpr is not available, but I would think that if I could do it with methods the compiler would eventually inline the function calls anyway - possibly as constants.

I read through the docs, and it doesn’t seem possible.

I got it kind of working here https://go.dev/play/p/5ztum5NAkUp but I would really like it to be method based rather than standalone function based, and the method based I would seemingly need to duplicate a lot of code for every possible number of decimal places.

What am I missing? Ideas?

Thanks for the help.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/fb1a8dd2-e1d6-499d-aabb-683afc8720a1n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/BC05C1B0-2D38-4FD9-B0E7-45B9A196B923%40ix.netcom.com.

Reply via email to