Am 29.07.2015 um 17:22 schrieb Don:

Related to this: it should not be importing std.bigint. Note that if
std.bigint were fully implemented, it would be very heavyweight (optimal
multiplication of enormous integers involves fast fourier transforms and
all kinds of odd stuff, that's really bizarre to pull in if you're just
parsing a trivial little JSON config file).

Although it is possible for JSON to contain numbers which are larger
than can fit into long or ulong, it's an abnormal case. Many apps
(probably, almost all) will want to reject such numbers immediately.
BigInt should be opt-in.

BigInt is opt-in, at least as far as the lexer goes. But why would such a number be rejected? Any of the usual floating point parsers would simply parse the number and just lose precision if it can't be represented exactly. And after all, it's still valid JSON.

But note that I've only added this due to multiple requests, it doesn't seem to be that uncommon. We *could* in theory make the JSONNumber type a template and make the bigint fields optional. That would be the only thing missing to making the import optional, too.


And, it is also possible to have floating point numbers that are not
representable in double or real. BigInt doesn't solve that case.

It might be adequate to simply present it as a raw number (an
unconverted string) if it isn't a built-in type. Parse it for validity,
but don't actually convert it.

If we'd have a Decimal type in Phobos, I would have integrated that, too. The string representation may be an alternative, but since the weight of the import is the main argument, I'd rather choose the more comfortable/logical option - or probably rather try to avoid std.bigint being such a heavy import (such as local imports to defer secondary imports).

Reply via email to