CPC Basic

Basic cross-compiler for Amstad CPC

    REAL operations



    Posts : 16
    Join date : 2012-03-16

    REAL operations

    Post  poppichicken on Mon Mar 19, 2012 1:04 am

    Hi Dinoneno.

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

    I am trying to do something like this:


    10 A=0.7^5*200
    20 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)


    100 p0=0:p1=1:p2=2:m0=3:m1=4 ' indexes of real values
    110 |CREAL,p1,0.7
    120 |CREAL,p2,5
    130 |POW,p0,p1,p2
    140 |CREAL,m1,200
    150 |MUL,m0,p0,m1
    160 |CINT,@a,m0
    170 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?


    [*** EDIT ***]

    I think I have solved it!


    10 p0=0:p1=1:m0=2:m1=3:d0=4:d1=5:d2=6 ' indexes of real values
    20 |CREAL,d1,7
    30 |CREAL,d2,10
    40 |DIV,d0,d1,d2 ' d0 = 7/10 = 0.7
    50 |CREAL,p1,5
    60 |POW,p0,d0,p1
    70 |CREAL,m1,200
    80 |MUL,m0,p0,m1
    90 |CINT,@a,m0
    100 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?


    Posts : 10
    Join date : 2012-03-11

    Re: REAL operations

    Post  Dinoneno on Mon Mar 19, 2012 2:32 am

    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.


    Posts : 16
    Join date : 2012-03-16

    Re: REAL operations

    Post  poppichicken on Mon Mar 19, 2012 11:40 am

    Thanks for the tip about |VAL.
    I'll give it a try.

    Sponsored content

    Re: REAL operations

    Post  Sponsored content

      Current date/time is Fri Dec 14, 2018 4:08 pm