compiling Giac with C++11

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

lukamar
Messages : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

compiling Giac with C++11

Message par lukamar » mer. avr. 04, 2018 8:18 am

Hello Bernard,
would Giac compilation fail if the header random.h was included? It belongs to C++11 standard, so I'm not sure. I would like to use it in some new code that I'm preparing. Thanks!

parisse
Messages : 5082
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: compiling Giac with C++11

Message par parisse » mer. avr. 04, 2018 4:30 pm

It would probably fail with some compilers I'm using. At some point, I know that I'll need to switch to C++11 but I'm not impatient because I fear it will raise some headdaches. What random functions do you need?

lukamar
Messages : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: compiling Giac with C++11

Message par lukamar » jeu. avr. 05, 2018 6:58 am

I need simple stuff, just generating a random integer in the given range [m,n) and the standard Gaussian random variable (mean=0 and stddev=1). The latter could be obtained by Box-Muller algorithm, while the former is as easy as m+rand()%(n-m), but it is in fact not uniform (lower numbers are slightly more likely to be returned). I know that Giac implements a better algorithm somewhere, can you point me to it please? I'm using STL containers of integers for speed, so i would like to avoid using gen class when generating random numbers (otherwise they would be easy to obtain by _rand), if possible.

parisse
Messages : 5082
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: compiling Giac with C++11

Message par parisse » jeu. avr. 05, 2018 7:53 am

giac_rand(contextptr) returns a random integer between 0 and rand_max2 (included) and randNorm(contextptr) returns a random double according to the normal law.

lukamar
Messages : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: compiling Giac with C++11

Message par lukamar » jeu. avr. 05, 2018 5:30 pm

Thanks! I'll then use giac_rand(ctx)/(rand_max2+1.0) for generating a real in [0,1[ and giac_rand(ctx)%n for an integer in [0,n-1].

Répondre