public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/111747] New: Problem with large float list initialization
@ 2023-10-09 22:04 oplata.kes1 at mail dot ru
  2023-10-10  1:50 ` [Bug libstdc++/111747] " pinskia at gcc dot gnu.org
  2023-10-10 19:52 ` oplata.kes1 at mail dot ru
  0 siblings, 2 replies; 3+ messages in thread
From: oplata.kes1 at mail dot ru @ 2023-10-09 22:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111747

            Bug ID: 111747
           Summary: Problem with large float list initialization
           Product: gcc
           Version: 11.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: oplata.kes1 at mail dot ru
  Target Milestone: ---

Created attachment 56085
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56085&action=edit
*ii file and output

I create a vector on stack of 50 (or 500mln) floats equal to 1.0 and simply add
them.
The sum is not equal to 50 mln (or 5 billions).

5 mln of floats initizalize and sum fine.

The command is

g++ -v -save-temps gcc.cpp && ./a.out

If it is a stack overflow, shouldn't the code fail with stack overflow error?
If not, what is it?

I use GCC 11.4.0 in Ubuntu 22.04 under WSL 2 (!)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libstdc++/111747] Problem with large float list initialization
  2023-10-09 22:04 [Bug libstdc++/111747] New: Problem with large float list initialization oplata.kes1 at mail dot ru
@ 2023-10-10  1:50 ` pinskia at gcc dot gnu.org
  2023-10-10 19:52 ` oplata.kes1 at mail dot ru
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-10  1:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111747

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---


32bit floating point has the following characteristics:
Sign bit: 1 bit
Exponent width: 8 bits
Significand precision: 24 bits (23 explicitly stored)


50000000 is 0x2faf080 which is more than 24bits in precision which means it
cannot be represented exactly and when you start to add 1 to something which is
greater than 0xfffff0 (which is what 1.67772e+07 is), the value stays the same
and you start to lose precision.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libstdc++/111747] Problem with large float list initialization
  2023-10-09 22:04 [Bug libstdc++/111747] New: Problem with large float list initialization oplata.kes1 at mail dot ru
  2023-10-10  1:50 ` [Bug libstdc++/111747] " pinskia at gcc dot gnu.org
@ 2023-10-10 19:52 ` oplata.kes1 at mail dot ru
  1 sibling, 0 replies; 3+ messages in thread
From: oplata.kes1 at mail dot ru @ 2023-10-10 19:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111747

--- Comment #2 from oplata.kes1 at mail dot ru ---
(In reply to Andrew Pinski from comment #1)
> 
> 32bit floating point has the following characteristics:
> Sign bit: 1 bit
> Exponent width: 8 bits
> Significand precision: 24 bits (23 explicitly stored)
> 
> 
> 50000000 is 0x2faf080 which is more than 24bits in precision which means it
> cannot be represented exactly and when you start to add 1 to something which
> is greater than 0xfffff0 (which is what 1.67772e+07 is), the value stays the
> same and you start to lose precision.

Thank you very much!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-10 19:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 22:04 [Bug libstdc++/111747] New: Problem with large float list initialization oplata.kes1 at mail dot ru
2023-10-10  1:50 ` [Bug libstdc++/111747] " pinskia at gcc dot gnu.org
2023-10-10 19:52 ` oplata.kes1 at mail dot ru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).