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

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

[Octave-bug-tracker] [bug #61143] Functions sum and mean returns wrong a


From: anonymous
Subject: [Octave-bug-tracker] [bug #61143] Functions sum and mean returns wrong answer for single precision input
Date: Sat, 11 Sep 2021 10:49:21 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0

URL:
  <https://savannah.gnu.org/bugs/?61143>

                 Summary: Functions sum and mean returns wrong answer for
single precision input
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Sat 11 Sep 2021 02:49:20 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: 6.2.0
         Discussion Lock: Any
        Operating System: Microsoft Windows

    _______________________________________________________

Details:

I use single precision to avoid memory overflow, and the input data is 2 byte
integer wave file. No need for double precision. 
The mean function does give incorrect answer and this I think is because the
sum function also gives wrong answer.


>> x=single(100*ones(100e+6,1));  % 100 million samples
>> sum(x)                         % should be 1.0000e+10
ans = 2.1475e+09                  % wrong answer 
>> x=single(100*ones(50e+6,1));   % 50 million samples
>> sum(x)
ans = 2.1475e+09                  % same wrong answer

% try with shorter vectors, OK first at 6e+5 samples
>> x=single(100*ones(6e+5,1));
>> sum(x)
ans = 6.0000e+07                  % correct answer

sum(x,'double') or sum(double(x)) solves the problem
mean(x,'double') does not solve this.
mean(double(x)) does solve this.


I think that the functions should return correct answer, and if that not is
possible send an error message.






    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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