emanuele
emanuele

Reputation: 2589

convert integer to long double

I have to create a long double random generator. I am thinking about a linear congruential generator, because I don't need high precision random sequence. But how can I convert an integer to a long double?

Upvotes: 2

Views: 1955

Answers (1)

wallyk
wallyk

Reputation: 57804

The conversion is implied when assigned. (Tested with gcc):

   program test
   integer  i
   real*10 d

   i = 10000
   i = i * 101
   d = i
   write (*,*) 'result is', d
   end

... amended ...
I was concerned there was something about the extended types which don't work well, I created a more thorough test:

   program test
   integer  i
   real     f
   double precision d
   real*10  ld

   i = 100000
   i = i * 101 + 101
   f = i * 1.1
   d = f * 1.1
   ld = d * 1.1
   write (*,*) 'result is', i, f, d, ld
   end


[wally@zenetfedora ~]$ ./a.out
 result is    10100101   11110111.       12221122.364885688        13443234.892748519537      

Upvotes: 1

Related Questions