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

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

[Octave-bug-tracker] [bug #63282] Make dec2base accept negative and/or f


From: Arun Giridhar
Subject: [Octave-bug-tracker] [bug #63282] Make dec2base accept negative and/or fractional inputs
Date: Thu, 23 Feb 2023 09:10:36 -0500 (EST)

Follow-up Comment #3, bug #63282 (project octave):

@nrjank: clarification. Did you mean that Matlab 2022b uses left-leading zeros
like Octave or does it pad with ones like Matlab 2020b?

Reading through the dec2bin.m history of why I wrote it that way, I found this
comment of mine from Sep 2022: https://savannah.gnu.org/bugs/?63089#comment6


The practice of left-padding with ones for negative inputs is standard two's
complement notation, but the practice of further left-padding that with zeroes
is not mathematically sound at all. Is Matlab still doing that or have they
fixed it to consistently left-pad with ones for all negative inputs? In any
case, I've added a note to the docstring explaining what to expect.


and `help dec2bin` states:

     For negative elements of D, return the binary value of the two’s
     complement.  The result is padded with leading ones to 8, 16, 32,
     or 64 bits as appropriate for the magnitude of the input.  Positive
     input elements are padded with leading zeros to the same width.  If
     the second argument LEN exceeds that calculated width, the result
     is further padded with leading zeros, for compatibility with
     MATLAB.


So Matlab was left-padding with zeros at some point in the past? I guess they
have fixed it now, so we can make ours consistent. I'll get to it in the next
several days, unless someone wants to go ahead earlier.


    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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