[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negativ
From: |
Mayeul Cantan |
Subject: |
[Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16 |
Date: |
Wed, 21 Sep 2022 10:51:58 -0400 (EDT) |
URL:
<https://savannah.gnu.org/bugs/?63089>
Summary: dec2bin gives wrong answer for negative int16
Project: GNU Octave
Submitter: mayeulc
Submitted: Wed 21 Sep 2022 02:51:57 PM UTC
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Incorrect Result
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Release: 7.2.0
Discussion Lock: Any
Operating System: GNU/Linux
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Wed 21 Sep 2022 02:51:57 PM UTC By: Mayeul Cantan <mayeulc>
Consider:
> dec2bin(int16(-4200))
ans = 111111111111111
> dec2bin(int32(-4200))
ans = 1110111110011000
-4200 obviously fits in a 2-complemented signed 16 bit integer, this is a bug.
The first line should return the same result as the second one.
While I am at it:
Octave:1> dec2bin(int32(-4200), 32)
ans = 00000000000000001110111110011000
Octave:2> dec2bin(int32(-42000))
ans = 1111111111111111111111111111111
Octave:3> dec2bin(-42000)
ans = 11111111111111110101101111110000
Octave:1 -- The leading zeroes should be leading ones for negative integers in
2-complement.
Octave:2 -- This is doubly wrong: wrong number of digits, and wrong result.
The next line shows a seemingly-correct result
There seems to be some of the same behaviours with i64, but I'm soon hitting
"dec2bin: negative inputs cannot be less than -flintmax () / 2".
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?63089>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16,
Mayeul Cantan <=
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Nicholas Jankowski, 2022/09/21
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Mayeul Cantan, 2022/09/21
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Markus Mützel, 2022/09/23
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Nicholas Jankowski, 2022/09/23
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Arun Giridhar, 2022/09/24
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Arun Giridhar, 2022/09/24
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Arun Giridhar, 2022/09/24
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, A.R. Burgers, 2022/09/24
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Arun Giridhar, 2022/09/25
- [Octave-bug-tracker] [bug #63089] dec2bin gives wrong answer for negative int16, Arun Giridhar, 2022/09/28