4 ms·
What are you going to do for currency amounts if you do not have ints ? Strings with numbers in them?
by sedachv 10y ago
What are you going to do for currency amounts if you do not have ints ? Strings with numbers in them?
- SamReidHughes 10y agoFloating point numbers handle integer values in the range -2^53..2^53 just fine.
- jnordwick 10y agoYou can definitely get around the currency issue by scaling yourself, but things like the timestamp issues (fractional seconds since the epoch with millisecond precision) are a little more problematic. You basically have to roll your own datetime format and lose any db support. Databases are about data after all. Why not have a rich way to describe it?
- SamReidHughes 10y agoI think so too. But I don't think, say, not having a 32-bit integer type, and 16-bit and 8-bit integers, is a big problem, if you've got doubles. Maybe it's a nice-to-have. A 64 bit type or bigint would add real value.
- jnordwick 10y agoI think as far as number types, you NEED (in the you should be considered seriously broken even if you can hobble along without) to have: - a 64-bit float - a 64-bit int everything else can be emulated in code from there and you can play all the encoding games you want to save space when you don't have to use it. This covers 99.999% of the use cases you reasonably see. From there, I would argue, you should also have: - a bit and byte - 32-bit ints - 32-bit float - 128-bit int (once you add UUIDs you might as well make them full numerics citizens). If I were doing a modern database, I'd have the kitchen sink as a type full numerics from 8 to 128 bit both signed and unsigned int and all supported hardware float sizes. I'd probably even have a 512-bit AVX type just to see what people would use it for.
- Dylan16807 10y agoWhy do you NEED a 64 bit int? Why not 32 bit? You're not storing pointers in a database. (And then you can implement your 32 bit int in terms of the 53 bits of int-capacity in a double.)
- jnordwick 10y agodatetimes, aggregations, etc. pretty much anything non-toy in the modern world requires 64 bit int. like I said. read NEED as in you can certainly hobble around without it (pick an appropriate offset and read your 53 bits in relation to it), but like a fracture in a leg, it's still considered broken.
- Dylan16807 10y agoWhat exactly do you mean by aggregations here? If you want a good timestamp you probably want a timespec, and that won't fit in 64 bits anyway. I don't see why it's easy to make 128+ bit types be composite, but you can't have 64 bit types be composite. Your database driver can take care of how the bits are packed on the wire. It really shouldn't be a big concern.
- jnordwick 10y agoprobably easier to have this convo in email (check my profile). HN iisn't quite setup for back and forth. I'm more than willing to see your point about about a 53-bit int. I think dev experience can be made more difficult as long as a you get compensation in other areas. Email me a "hi" and I'll respond, but it might have to wait until later in the day.
- SamReidHughes 10y agoA query optimizer might do a lot better with a native integer type than a user-defined one cobbled out of int32's. It knows all the mathematical properties of the type and add things in any order, knows that x < y implies x + 1 <= y, etc.
- 10y ago