back

by uecker·2y ago·view on hn ↗
Look at any C program. What are integers used for? Counting things, loop indexing, etc. These are all semantics of mathematical integers. Yes, it is an approximation that only works as integers do not get too big. But the limits are still bigger than most numbers people do use in their daily lives. Most people could not calculate with higher number in their head, are you saying their mental model of integers is a small integer model different from mathematical model? This misunderstands the purpose of mathematical abstractions at a fundamental level.

Big number integers also has use cases, but this is has very special purposes. And also big numbers are not "true" mathematical numbers if you want to be really pedantic, because if you memory is limited also this abstraction breaks downs at some point. Models for true mathematical integers do not exist in the physical world, so that "int" isn't one, is meaningless pedantry.

1 comments
> Look at any C program. What are integers used for? Counting things, loop indexing, etc.

Both of those should use unsigned integers, and they are limited by the size of the machine, so no, they don't need a mathematical model of integers. A good machine will have a size_t size that can hold any size of object, and by extension, any number of elements of any size, including char.

So for counting things and loop indices, size_t should be used, not any signed types.

In my code, I essentially use just size_t and unsigned char (because the standard did not specify the signedness of char up to at least C11). If I use something else, I am checking bounds.

> Most people could not calculate with higher number in their head, are you saying their mental model of integers is a small integer model different from mathematical model?

Are you seriously trying to accuse me of this? I am the one saying that hardware integers are not a sufficient abstraction for mathematical integers, yet you say that I assume that people have a small integer mental model?

No, I am not. I am the one telling you that using hardware integers in place of big ints is not good.

> Models for true mathematical integers do not exist in the physical world, so that "int" isn't one, is meaningless pedantry.

True, every abstraction is leaky, but big integers and rationals can get so large that it doesn't matter.

And yes, big ints are a leaky abstraction, but they leak so much less than hardware integers because they don't wrap and because they are not subject to 00UB when unsigned types are used.