[Bugzilla] [Bug 15509] New: int8 an iconvert pages are ambiguous about conversion from double

bugzilla.admin at scilab.org bugzilla.admin at scilab.org
Wed Mar 28 15:53:44 CEST 2018


http://bugzilla.scilab.org/show_bug.cgi?id=15509
--------- Bug Summary -----------
int8 an iconvert pages are ambiguous about conversion from double

---------- Changed by ------------
stephane.mottelet at utc.fr

---------- What changed ----------
bug_id, short_desc, product, version, rep_platform, op_sys, bug_status, bug_severity, priority, component, assigned_to, reporter


            Bug ID: 15509
           Summary: int8 an iconvert pages are ambiguous about conversion
                    from double
           Product: Scilab software
           Version: 6.0 nightly or development
          Hardware: (not used)
                OS: All OS
            Status: NEW
          Severity: Minor
          Priority: (field not used)
         Component: Documentation pages
          Assignee: bugzilla.admin at scilab.org
          Reporter: stephane.mottelet at utc.fr

When the value of a double x is greater that the maximum value of integer type and lower than M=2^53, i.e. the greatest integer such that *every*
integer such that n<=M is exactly represented as a double, then the conversion done by int8(x),uint8(x),...,int32(x),uint32(x) is done by a
truncation of fractionnal part followed by a wrapping. If 2^64-1 > x > 2^53, there will be a loss of precision but the behavior is still predictable,
but int64 and uint64 won't be able to do any wrapping because there is a complimentary problem when x>=2^64 :

In this case no value of x can be represented in the largest integer type, i.e. uint64. For example, the result of 

uint64(2^64)

is platform dependent and maybe for Windows even compiler dependent (see bug #15506). As explained in

https://stackoverflow.com/questions/33824954/cast-from-unsigned-long-long-to-double-and-vice-versa-changes-the-value

"A prvalue of a floating point type can be converted to a prvalue of an integer type. The conversion truncates; that  is, the fractional part is
discarded. The behavior is undefined if the truncated value cannot be represented in the destination type. So this code potentially causes undefined
behaviour. When undefined behaviour has occurred, anything can happen, including (but not limited to) bogus output."

Maybe the help page should mention this.

-- 
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/bugzilla/attachments/20180328/6b9aba06/attachment.htm>


More information about the Bugzilla mailing list