CPC Basic

# REAL operations

poppichicken

Posts : 16
Join date : 2012-03-16
Hi Dinoneno.

I have a quick question about using the RSX functions for REALs.

I am trying to do something like this:

Code:
`10 A=0.7^5*20020 PRINT A`

When I run this in WinAPE as a BASIC program, it prints 33.614.

I want to do this in CPC Basic 3.

So far I have this:
(Note that I have the Real Numbers set to 5 in the IDE)

Code:
`100 p0=0:p1=1:p2=2:m0=3:m1=4 ' indexes of real values110 |CREAL,p1,0.7120 |CREAL,p2,5130 |POW,p0,p1,p2140 |CREAL,m1,200150 |MUL,m0,p0,m1160 |CINT,@a,m0170 PRINT a`

When this is compiled and run, it prints 200.
I expected it to print 34, which is 33.614 rounded up.
It looks as though line 110 is putting 1 into pow1 instead of 0.7.

I don't understand what I am doing wrong.
Can you help me?

Thanks.

[*** EDIT ***]

I think I have solved it!

Code:
`10 p0=0:p1=1:m0=2:m1=3:d0=4:d1=5:d2=6 ' indexes of real values20 |CREAL,d1,730 |CREAL,d2,1040 |DIV,d0,d1,d2 ' d0 = 7/10 = 0.750 |CREAL,p1,560 |POW,p0,d0,p170 |CREAL,m1,20080 |MUL,m0,p0,m190 |CINT,@a,m0100 PRINT a`

This prints 34 as expected.

A little question - is it possible to set the number of real numbers in the program itself, instead of a the top of the IDE?

Dinoneno

Posts : 10
Join date : 2012-03-11
You've solved the problem perfectly for the value 0.7. Occurs when a |CREAL pass the value 0.7, CPC Basic (and makes it equal Locomotive Basic) passes the rounded value, ie 0.7 does not pass, but 1. You can also use |VAL,p1,"0.7" and need not divide 7/10.

No, for now there is no possibility to define in the program the number of real variables to be used, but it will count as a possible improvement. In compiling from the command line does exist a parameter that can indicate.

poppichicken

Posts : 16
Join date : 2012-03-16
Thanks for the tip about |VAL.
I'll give it a try.