octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #62283] max (a, b) produces unintuitive result


From: Markus Mützel
Subject: [Octave-bug-tracker] [bug #62283] max (a, b) produces unintuitive results when mixing integers and floating point values
Date: Sun, 5 Jun 2022 07:20:15 -0400 (EDT)

Follow-up Comment #7, bug #62283 (project octave):

I'm not sure the wording in that documentation change is correct.
IIUC, usually integer promotion only refers to promotion of some integer type
value to a larger integer type. When a value changes type from integer to
floating point, that is usually called "casting".

The "normal" rule in Octave (and Matlab) is to not allow operations between
mixed integer type values. Floating point types are implicitly casted to
integer types in mixed floating point-integer operations. Double precision
floating-point types are implicitly casted to single precision in mixed
single-double floating point operations.
In general, I understand the rule is: Double precision floating point numbers
are the "default type". If there is an operation involving another type, the
user needed to explicitly select that type. So the assumption is that the user
would like to keep with the type they explicitly selected (and not switch to
the "default" type again and again).
Matlab is a bit stricter than Octave when it comes to that rule: It forbids
operations between integer type and single precision floating point numbers.
Octave implicitly casts to the integer type in that case (like it would do in
mixed double precision floating point-integer operations).

Some functions explicitly cast integer type input to double. Others,
automatically promote explicitly to the larger integer type. But those are
kind of "exceptions to the rule".


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?62283>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]