PowerBasic / FreeBasic / PureBasic compared with double

Started by Marc Pons, November 19, 2012, 12:10:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Marc Pons

I was testing the performance of PowerBasic / FreeBasic / PureBasic with double values and i noticed something wrong wih Powerbasic :
see under  extracted code


'it =   10000000 cycles
    ReDim MonTableau(1 to it)         AS double   
    I = 1 ' As long
    val1 = 2.456 ' AS double
    val2 = 5.567 ' AS double
    tStart = Timer
    While I < it + 1
        val3 = val1 * val2 * I   '  val3 AS double
        MonTableau(I) = val3
        I = I + 1
    Wend
    tEnd = Timer
   
    'MonTableau(it) should be > 136725520     but powerbasic gives  136725522.835712

The speed comparing to / FreeBasic / PureBasic is almost 1/2 time ... but wrong results (bad precision)
FreeBasic / PureBasic, both giving the right values

I tested with   As Ext  > same speed but still wrong values
I tested with   As Cur  > good precision but at least 2 times slower than FreeBasic / PureBasic

Some advices from you guys ? am I doing something wrong ?

Marc

José Roca

> am I doing something wrong ?

Yes. You are assigning single precision values to double precision variables. Use:

val1 = 2.456#
val2 = 5.567#

Marc Pons

Thanks a lot  _ it works great

I was thinking , if the variable  is defined as Double it was enought to assign with floating value, obviously it is not.
With the # it is perfect.

After testing your proposal , i tried other possibility ,it works also like that

val1 = 2.4560000000000000000
val2 = 5.5670000000000000000

And with your advice ( or with long values as above)  the speed of PowerBasic compared to
FreeBasic (0.24) or PureBasic (4.61)  is more than 2 times faster  for 10 000 000 iterations : 170 ms
when with Free/Pure around 360 ms on my old PC  (Intel Pentium M 1500Mhz/ under XP3)

Thanks again José for the advice and the speed of your answer.
Marc