1
$\begingroup$

Wikipedia defines range of data type:

the set of possible values that that variable can hold.

Suppose we have two data types A and B. Now, with attention to the definition of widening in section 7.4 of Concepts of Programming Languages, we can say:

range of B is larger than A when range of B includes at least approximations of all members of range of A.

But above definition is informal; because "accuracy" of approximation is not determined. For example we can consider 0 as approximate for 0 of int and 1 as approximate for all other members of int. So we give a strange statement:

range of int ≤ range of {0,1}

Although we can add the |A| ≤ |B| as a criteria to avoid some strange statements like above one (|A| means Cardinal number for set A); but the problem of "accuracy" remains again.

Do you know a formal definition for "a data type with larger range"?

$\endgroup$
3
  • $\begingroup$ $1$ being an approximation for all nonzero integers is pretty abusive, though they say that some tribes count with "one, two, many". $\endgroup$
    – user16034
    Commented Sep 9, 2022 at 9:31
  • 2
    $\begingroup$ Why do you feel the need for a formal definition ? $\endgroup$
    – user16034
    Commented Sep 9, 2022 at 9:35
  • 1
    $\begingroup$ You're placing too much faith in Wikipedia, and in any case you are trying to define formally a phrase that has several possible meanings, of which Wikipedia lists two (range of a numeric type, range of an array). If you seek more formal and more exact understanding, the first step is to not read Wikipedia and open a textbook. We can suggest one if you tell us what you're after in the grander scheme of things. $\endgroup$ Commented Oct 9, 2022 at 10:11

1 Answer 1

1
$\begingroup$

$$B_{\text{min}}\le A_{\text{min}}\land B_{\text{max}}\ge A_{\text{max}}$$

should do (with the implicit assumption that the types $A$ and $B$ are appropriate to represent numbers).

$\endgroup$
6
  • $\begingroup$ You're assuming that the datatypes in question are linearly ordered and that an inclusion of $A$ into $B$ is understood. $\endgroup$ Commented Oct 9, 2022 at 10:09
  • $\begingroup$ @AndrejBauer: numbers are known to be linearly ordered $\endgroup$
    – user16034
    Commented Oct 10, 2022 at 10:32
  • $\begingroup$ The OP never mentioned numbers (except for cardinal numbers at the end), so at least I never guessed they were discussing numerical datatypes. Also, complex numbers are not linearly ordered, but that's not important. $\endgroup$ Commented Oct 10, 2022 at 12:46
  • $\begingroup$ @AndrejBauer: from the book: "Type conversions are either narrowing or widening. A narrowing conversion converts a value to a type that cannot store even approximations of all of the values of the original type. For example, converting a double to a float in Java is a narrowing conversion, because the range of double is much larger than that of float. A widening conversion converts a value to a type that can include at least approximations of all of the values of the original type." $\endgroup$
    – user16034
    Commented Oct 10, 2022 at 13:12
  • $\begingroup$ I don't think people are required to read books referred to to understand questions. The term datatype is much more general than numeric datatype, and that's how I understood it. In any case – whatever, it's not important, enjoy my upvote. $\endgroup$ Commented Oct 10, 2022 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.