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

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

[Octave-patch-tracker] [patch #8161] rand: When initializing MT with vec


From: Philipp Kutin
Subject: [Octave-patch-tracker] [patch #8161] rand: When initializing MT with vector, handle out-of-range values consistently.
Date: Thu, 15 Aug 2013 18:23:10 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:23.0) Gecko/20100101 Firefox/23.0

URL:
  <http://savannah.gnu.org/patch/?8161>

                 Summary: rand: When initializing MT with vector, handle
out-of-range values consistently.
                 Project: GNU Octave
            Submitted by: pkutin
            Submitted on: Thu 15 Aug 2013 06:23:09 PM GMT
                Category: None
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

* oct-rand.cc: Add function double_to_uint32(). It normalizes a finite double
by taking it modulo 2^32, such that the result is in [0, 2^32). Nonfinites
give zero as result. This prevents an otherwise occuring cast of a double
whose truncated value cannot be represented in a uint32_t, which is undefined
behavior.
* rand.cc: Add a test block.

--

The only thing I'm unsure about is that I'm using plain 'fmod' for the
remainder instead of something like 'gnulib::fmod' which you seem to prefer. I
tried that, but the compiler complained that there was no such function.
(Configuration issue?)

No attempt has been made to have 100% the same behavior as MATLAB. The
important point is that no undefined behavior is executed on out-of-range
values (tested using a sanitized Clang build), and it is also desirable that
the mapping is in a sense as uniform as possible.



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Thu 15 Aug 2013 06:23:09 PM GMT  Name:
rand-When-initializing-MT-handle-out-of-range-1.patch  Size: 2kB   By: pkutin

<http://savannah.gnu.org/patch/download.php?file_id=28856>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/patch/?8161>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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