2

Some programing languages, notably Pascal, have a type of numbers called "real".

However, mathematically speaking, these types aren't real. For them to be "real", these types have to be able to represent any real number. Real numbers like 1/3 and irrationals, however, can't be represented in floating point. So why do some programing languages call these types "real"?

Niccolo M.
  • 263
  • 2
  • 7
  • 4
    *Real* numbers were introduced as distinct from *integer* numbers. Both Algol and Fortran pre-date Pascal and use "real" to mean non-integers. – BobDalgleish Jul 18 '14 at 14:35
  • 3
    The `int` type doesn't really denote integers in most languages either. The use of `unsigned int` instead of `nat` or `natural` is a bit perplexing though. – Doval Jul 18 '14 at 14:39
  • 10
    Many languages also habe a type called "integer" which cannot represent all integers. – Jörg W Mittag Jul 18 '14 at 14:47
  • 1
    Calling them `rational` would lead to the expectation that exact rational arithmetic could be performed. – AakashM Jul 18 '14 at 15:04
  • @AakashM in fact, `rational` is quite as misguided, as they cannot represent most the rational numbers either. – SJuan76 Jul 18 '14 at 15:11
  • 2
    I think you have the question backwards. At a time when most of the existing languages were using "real" to mean floating-point (as opposed to integer), C chose to use "float" instead of "real". Your question could just as easily, and more correctly IMHO, be stated as "Why does C (and its derivatives) use "float" instead of "real" to denote (machine-approximate, i.e., floating-point) real numbers?". – John R. Strohm Jul 18 '14 at 16:18
  • Of course `1/3` can be represented with absolute accuracy in a floating-point number system, though not, I grant you, a binary f-p number system. – High Performance Mark Jul 18 '14 at 18:26
  • @Doval: What makes the use of `unsigned int` particularly curious is that integer types are never required to behave in a fashion contrary to the rules of integer arithmetic (if `x` and `y` are of type `int`, but the sum `x+y` would not be representable, the standard would allow a program to do anything it likes, up to and including destroying the universe, rather than computing an incorrect value) but `unsigned` types are in many though not all cases required to behave in a fashion contrary to the rules of integer arithmetic. – supercat Sep 15 '14 at 18:57
  • You are more right than you say. No computer can represent real numbers because there are uncountably many of them. No computer can represent *integers* either because there are infinitely many integers and (in the known universe) only finitely many representations of them. – Martin Kochanski Sep 02 '22 at 05:57
  • Also note that some languages have a built-in `complex` floating-point type, which `real` numbers are contrasted with. – dan04 Sep 02 '22 at 16:20

2 Answers2

11

Short answer: because it is the default approximation of a real number the language in question provides.

Doc Brown
  • 199,015
  • 33
  • 367
  • 565
0

All Pascal float values are actually real numbers. In C or C++ you also have -0, +/-inf and +/-NaN which are not real numbers, but practically most floats that you use are real numbers.

gnasher729
  • 42,090
  • 4
  • 59
  • 119
  • So what? Half of what you said is in my answer, the rest is irrelevant to the question Pascal, when it was invented, had no floating point numbers that were not real. Your reading is totally irrational. So try again, with some effort this time. After reading the question, maybe. – gnasher729 Aug 31 '22 at 13:46
  • All rational numbers, floating point numbers and integers are real numbers. But it would be really confusing if Pascal called integer types "real" too. – Simon B Sep 01 '22 at 10:11
  • Simon B, and there are reasons not to put tomatoes into a fruit salad. – gnasher729 Sep 02 '22 at 10:47