mailing list of musl libc
 help / color / mirror / code / Atom feed
* Re: drand48() gives wrong sequence?
@ 2014-09-21 12:20 Nadav Har'El
  2014-09-21 12:40 ` Jens Gustedt
  0 siblings, 1 reply; 5+ messages in thread
From: Nadav Har'El @ 2014-09-21 12:20 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1130 bytes --]

>Am Sonntag, den 21.09.2014, 14:45 +0300 schrieb Nadav Har'El:
>> Any ideas why I'm getting the wrong sequence?
>
>I don't think you are getting the wrong sequence, you are just
>printing it wrong. "%ld" is for long double and not for double.
>
>Jens

(I tried to subscribe to the mailing list but it didn't work, so please CC
me with further responses).

"%ld" is not a double at all, it's an int.

My message's title was indeed somewhat confusing, because I mentioned
drand48() in the title but used lrand48() in my example code. I saw the
same problem of a different sequence also with drand48() (printed with %g
of course) - but at the end decided to include code which printed lrand48().

Anyway, "%ld" is the right thing to use here because lrand48() returns a
"long int".
Replacing it with "%d" makes no difference and the sequences are still
different (I tried). This is because while lrand48()'s type is officially
"long", its return value is just 32-bit, so one can treat it just fine as
either long (64-bit on my 64-bit machine) or int (32-bit) and you get the
same result.



-- 
Nadav Har'El
nyh@cloudius-systems.com

[-- Attachment #2: Type: text/html, Size: 1564 bytes --]

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

* Re: Re: drand48() gives wrong sequence?
  2014-09-21 12:20 drand48() gives wrong sequence? Nadav Har'El
@ 2014-09-21 12:40 ` Jens Gustedt
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Gustedt @ 2014-09-21 12:40 UTC (permalink / raw)
  To: musl; +Cc: Nadav Har'El

[-- Attachment #1: Type: text/plain, Size: 1050 bytes --]

Am Sonntag, den 21.09.2014, 15:20 +0300 schrieb Nadav Har'El:
> >Am Sonntag, den 21.09.2014, 14:45 +0300 schrieb Nadav Har'El:
> >> Any ideas why I'm getting the wrong sequence?
> >
> >I don't think you are getting the wrong sequence, you are just
> >printing it wrong. "%ld" is for long double and not for double.
> >
> >Jens
> (I tried to subscribe to the mailing list but it didn't work, so
> please CC me with further responses).
> 
> 
> "%ld" is not a double at all, it's an int.

> My message's title was indeed somewhat confusing, because I mentioned
> drand48() in the title but used lrand48() in my example code.

ah, right, still my association of %ld to long double was a bit hasty,
sorry for the noise.

Jens

-- 
:: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::




[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: drand48() gives wrong sequence?
       [not found] ` <CANEVyjv9wwEBibFjqV7XTLzBU2BLvpVPzvxig7ArGceOfpzY7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-09-21 13:27   ` Justin Cormack
  0 siblings, 0 replies; 5+ messages in thread
From: Justin Cormack @ 2014-09-21 13:27 UTC (permalink / raw)
  To: Nadav Har'El; +Cc: musl-ZwoEplunGu1jrUoiu81ncdBPR1lH4CV8, Osv Dev

On Sun, Sep 21, 2014 at 12:45 PM, Nadav Har'El <nyh-RmZWMc9puTNJc61us3aD9laTQe2KTcn/@public.gmane.org> wrote:
> Hi, I ran the following trivial program on both glibc (on Linux), and Musl
> (on OSv).
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main() {
>         srand48(12345);
>         printf("%ld %ld %ld\n", lrand48(), lrand48(), lrand48());
> }
>
> Unfortunately, the sequence did not come out the same: On glibc+Linux I got:
>
>      444188209 1973930609 483889296
>
> But on OSv+Musl I got:
>
>      1737082417 264424049 61706384
>
> I expected to get the same sequence because both the drand48(3) man-page on
> Linux and the drand48 specification in Posix
> (http://pubs.opengroup.org/onlinepubs/9699919799/functions/drand48.html) are
> pretty explicit about the formulas that should be used. I also looked at the
> Musl code quickly, and it does seem to use these formulas.
>
> Any ideas why I'm getting the wrong sequence?

Hmm, just checked on a non-OSv Musl system and get the same result as
you. I also checked on NetBSD and FreeBSD and they give the same
result as glibc, so I think there must be a Musl bug.

-- 
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.


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

* Re: drand48() gives wrong sequence?
  2014-09-21 11:45 Nadav Har'El
@ 2014-09-21 12:02 ` Jens Gustedt
       [not found] ` <CANEVyjv9wwEBibFjqV7XTLzBU2BLvpVPzvxig7ArGceOfpzY7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Jens Gustedt @ 2014-09-21 12:02 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 569 bytes --]

Hello,

Am Sonntag, den 21.09.2014, 14:45 +0300 schrieb Nadav Har'El:
> Any ideas why I'm getting the wrong sequence?

I don't think you are getting the wrong sequence, you are just
printing it wrong. "%ld" is for long double and not for double.

Jens


-- 
:: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* drand48() gives wrong sequence?
@ 2014-09-21 11:45 Nadav Har'El
  2014-09-21 12:02 ` Jens Gustedt
       [not found] ` <CANEVyjv9wwEBibFjqV7XTLzBU2BLvpVPzvxig7ArGceOfpzY7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Nadav Har'El @ 2014-09-21 11:45 UTC (permalink / raw)
  To: musl-ZwoEplunGu1jrUoiu81ncdBPR1lH4CV8; +Cc: Osv Dev

[-- Attachment #1: Type: text/plain, Size: 1194 bytes --]

Hi, I ran the following trivial program on both glibc (on Linux), and Musl
(on OSv).

#include <stdio.h>
#include <stdlib.h>

int main() {
        srand48(12345);
        printf("%ld %ld %ld\n", lrand48(), lrand48(), lrand48());
}

Unfortunately, the sequence did not come out the same: On glibc+Linux I got:

     444188209 1973930609 483889296

But on OSv+Musl I got:

     1737082417 264424049 61706384

I expected to get the same sequence because both the drand48(3) man-page on
Linux and the drand48 specification in Posix (
http://pubs.opengroup.org/onlinepubs/9699919799/functions/drand48.html) are
pretty explicit about the formulas that should be used. I also looked at
the Musl code quickly, and it does seem to use these formulas.

Any ideas why I'm getting the wrong sequence?

Thanks,
Nadav.

-- 
Nadav Har'El
nyh-RmZWMc9puTNJc61us3aD9laTQe2KTcn/@public.gmane.org

-- 
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 1797 bytes --]

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

end of thread, other threads:[~2014-09-21 13:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-21 12:20 drand48() gives wrong sequence? Nadav Har'El
2014-09-21 12:40 ` Jens Gustedt
  -- strict thread matches above, loose matches on Subject: below --
2014-09-21 11:45 Nadav Har'El
2014-09-21 12:02 ` Jens Gustedt
     [not found] ` <CANEVyjv9wwEBibFjqV7XTLzBU2BLvpVPzvxig7ArGceOfpzY7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-09-21 13:27   ` Justin Cormack

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).