Opened 11 years ago

Last modified 6 years ago

#6280 new Bugs

numeric_cast throws on exactly representable conversion

Reported by: Simeon Maxein <smaxein@…> Owned by: Douglas Gregor
Milestone: To Be Determined Component: numeric
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

If a double or float representing the smallest possible value of int64_t is cast to int64_t using numeric_cast, an exception is thrown saying that a negative overflow has occured.

I would expect the cast to work, since the value is exactly representable in the target type. Since the absolute value is a power of two, there should not be any error in the floating point representation.

This is also reproducable in trunk, according to VeXocide. I found the problem in Boost 1.47.0 on Windows, using MinGW 4.5.2.

Attachments (1)

main.cpp (272 bytes ) - added by Simeon Maxein <smaxein@…> 11 years ago.
Small test program

Download all attachments as: .zip

Change History (2)

by Simeon Maxein <smaxein@…>, 11 years ago

Attachment: main.cpp added

Small test program

comment:1 by wellnhofer@…, 6 years ago

This works for me with Boost 1.58 on Ubuntu, but ldrexp(1, 63) doesn't throw. See ticket #12252.

Note: See TracTickets for help on using tickets.