PaesslerAG / gval

Expression evaluation in golang
BSD 3-Clause "New" or "Revised" License
711 stars 83 forks source link

Hexadecimal support #96

Open jotego opened 1 year ago

jotego commented 1 year ago

Thank you for this great package.

It would be nice if 0x for hexadecimal numbers was usable by default. I think the way around it now is to define some sort of hex function within the application.

imirkin commented 1 year ago

Pretty sure the core tokenization logic supports it since it goes through scanner.Int. However parseNumber doesn't deal with it -- you could change that to fallback on strconv.ParseInt with a base of 0. (Just saying this based on glancing at the code, didn't do any actual tests.)

imirkin commented 1 year ago

Worth noting that gval's base/arithmetic language can't represent actual integers, only float64's. You'll run into precision issues once you go above 1<<53 in magnitude. But of course you could specify a language based on int64's, see e.g. how decimal is handled.