user2953119
user2953119

Reputation:

Mathematically defined result of an expression

What does mathematically defined result mean?

There is a quote from 5/4:

If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined.

Upvotes: 4

Views: 244

Answers (5)

n. m. could be an AI
n. m. could be an AI

Reputation: 120021

"Mathematically defined result" means the same thing it would mean in other similar contexts. Namely, there are constructs in most programming languages that represent, to that or another degree of accuracy, various mathematical concepts via some kind of natural mapping. This mapping is normally not defined in the documentation but is implied by reader's understanding of the natural language and common sense. In the C++ standard, it is referred in various places as "usual" or "ordinary" mathematical rules.

If you are unsure what this mapping is, I guess you can submit a defect report, but usually users of the standard know what 2+2 maps to, just as they know what words like if or the or appear or requirement mean.

It is true that 2+2 can be conceivably mapped to various mathematical constructs, not necessarily even connected to say Peano arithmetic, but that's not an "ordinary" or "usual" mathematics by the standards of C++ community.

So to answer the question, take an expression and map it to the corresponding mathematical concept. If it is not defined, then it is not defined.

Upvotes: 0

KKGanguly
KKGanguly

Reputation: 343

It depends on context. Mathematically not defined means simply: it is not defined under mathematics.
Suppose you want to divide by 0 but it is not defined : Division is the inverse of multiplication. If a \ b=c, then b * c=a.
But if b=0 , then any multiple of b is also 0 , and so if a != 0 , no such c exists.

On the other hand, if a and b are both zero, then every real number c satisfies b * c=a. Either way, it is impossible to assign a particular real number to the quotient when the divisor is zero. (From wikipedia).
In algebra, a function is said to be "undefined" at points not in its domain. In geometry,In ancient times, geometers attempted to define every term. For example, Euclid defined a point as "that which has no part". In modern times, mathematicians recognized that attempting to define every word inevitably led to circular definitions, and in geometry left some words, "point" for example, as undefined. So it depends on context.
In programming context, you can assume that it means divide by 0 or out of a defined range,causing overflow.

Upvotes: 0

MSalters
MSalters

Reputation: 179981

The mathematical way to state this would be that the behavior is undefined iff the inputs are not elements of the natural domain of the function.

(The second part, about results being representable, translates to a restriction on the codomain of the function)

Upvotes: 0

Yu Hao
Yu Hao

Reputation: 122443

There's a note right after this statement, which provides some types of examples:

[ Note: most existing implementations of C++ ignore integer overflows. Treatment of division by zero, forming a remainder using a zero divisor, and all floating point exceptions vary among machines, and is usually adjustable by a library function. —end note ]

Upvotes: 5

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145359

For example, 0/0 is not mathematically defined.

The case of 1/0 is slightly different, but in practice, for the C++ standard you can be sure that it's not viewed as mathematically defined.

Upvotes: 4

Related Questions