Bug 873385 - Random module fails on Doubles because of odd minBound behaviour
Summary: Random module fails on Doubles because of odd minBound behaviour
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: hugs98
Version: 21
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jens Petersen
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-11-05 17:31 UTC by Ian Collier
Modified: 2015-12-02 16:03 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2015-12-02 02:41:01 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Ian Collier 2012-11-05 17:31:23 UTC
I'm not sure how live this project is any more, but here goes...

$ rpm -q hugs98
hugs98-2006.09-11.fc17.x86_64

$ hugs
Type :? for help
Hugs> :load Random 
Random> randomR (1::Double,10) (mkStdGen 3)
(
Program error: arithmetic overflow

The equivalent answer in ghci is:
(1.928919588914141,2109513658 1655838864)

This seems to happen because:

Random> minBound::Int
-2147483648
Random> toInteger (minBound::Int)
-18446744071562067968
Random> toInteger (maxBound::Int)
2147483647

The implementation of Random on Doubles uses the construction
"toInteger (minBound::Int)" to get an integer random number, but
the implementation of Random on integers falls over on values
greater than 2^32-1.

Comment 1 Jens Petersen 2012-11-06 06:29:25 UTC
Ah I see.  I wonder if it is a 64 bit issue?

Unfortunately hugs is pretty much dead^Wunmaintained now AFAIK.

Anyway I will try to have a look at the code later and
maybe compare with the current random package and see
if I can come up with a patch... of course there could
be other 64bit problems lurking.

Comment 2 Fedora End Of Life 2013-07-04 02:30:48 UTC
This message is a reminder that Fedora 17 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 17. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '17'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 17's end of life.

Bug Reporter:  Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 17 is end of life. If you 
would still like  to see this bug fixed and are able to reproduce it 
against a later version  of Fedora, you are encouraged  change the 
'version' to a later Fedora version prior to Fedora 17's end of life.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 3 Jens Petersen 2013-07-11 10:15:17 UTC
Still happening with F19

Comment 4 Jens Petersen 2015-01-07 03:10:34 UTC
And still for F21 of course.

hugs98.i686 seems okay: so installed that by hand would be a workaround perhaps.

I tested on Ubuntu amd64 and got the same error
(I guess the Debian package also has this problem).

Comment 5 Jens Petersen 2015-01-07 06:55:17 UTC
(FWIW 64bit ghci gives:

Prelude> toInteger (minBound :: Int)
-9223372036854775808
)

Hugs seems to be assuming Int32, but something is indeed going
wildly wrong with "toInteger (minBound::Int)".

I looked at:

src/bignums.c:326:primFun(primIntToInteger) {		/* Conversion :: Int -> Integer	   */

but I am not familiar with hugs' internals and things
seems to get into deep water quickly.


BTW "toInteger (minBound + 1:: Int) -1"
and "toInteger (minBound -1:: Int) +1"
seem to give the expected answer.

I almost wonder if it would be better to drop 64bit arch build for hugs.

Comment 6 Fedora End Of Life 2015-11-04 15:46:26 UTC
This message is a reminder that Fedora 21 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 21. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '21'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 21 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 7 Fedora End Of Life 2015-12-02 02:41:04 UTC
Fedora 21 changed to end-of-life (EOL) status on 2015-12-01. Fedora 21 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.