1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Use of the SINGLE variable type in Oshonsoft Basic

Discussion in 'Oshonsoft' started by Mellbreak, May 29, 2012.

  1. Mellbreak

    Mellbreak New Member

    Joined:
    May 8, 2012
    Messages:
    5
    Likes:
    0
    Can anyone tell me if it is possible to use exponents in Oshonsoft BASIC? If I declare a variable type as "single", the following compiles.

    Dim xx As Single

    xx = 4294967296 * 180000000


    but...

    xx = 4294967296 * 180e6

    does not. I get the error "not a valid Single type constant."

    Am I using the wrong method to represent the exponent? Also tying to display the value of xx on an LCD gives some very odd results using Lcdout #xx.

    Any help gratefully received.
     
  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,178
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    Do you have the Math32 option from Oshonsoft.?

    The '#' prefix will only work for a maximum value of 65535 decimal, you will get incorrect results for higher than 65K.

    I have never seen the use of exponents with Oshonsoft

    EDIT,
    This a sample program to show the LONG to ASC conversion subr in ASM

    Copy and paste the 'bin2asc' section and its Dim's
     
    Last edited: May 29, 2012
  3. Mellbreak

    Mellbreak New Member

    Joined:
    May 8, 2012
    Messages:
    5
    Likes:
    0
    Thanks for the reply Eric. Yes I do have the Math32 option, but there seems little info out there to say how it is used. Thanks for the file - I'll have a look at your routine and see if I make use of it. If anyone does have any information regarding the use of the Single variable type or its structure I would appreciate any info.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    257
    Likes:
    15
    Location:
    Helsinki, Finland
    ONLINE

    I have not succeeded to declare single variable with exponent.
    Only information about single variable is on Oshhonsoft home page. It is 4 byte modified IEE754 format with 7-digit precision.
    Lcdout #x shows single variable with 7-digits
    eg. 98765.123 -> 98765.12
    9876.123 -> 9876.123
    98765432 and negative numbers display garbage.

    Single variable could be displayed with exponent in Lcdout by scaling it between 1-9 by multiplying or dividing by 10 and counting the exponent.
    For example positive single x greater than 10

    exponent=0 ' byte variable
    while x>=10
    x=x/10
    exponent=exponent+1
    wend

    then converting integer and decimal parts to long variables:

    i=x
    x2=x-i ' x2 is single
    j= 100000*x2 ' 6 digits decimal
    Lcdout #i,"."#j,"E",#exponent

    If x is smaller than 1 then repeat with multiplying by 10
    Lcdout #i,"."#j,"E-",#exponent

    Negative numbers should be handled separately eg. by first converting to positive with multiplying by -1.
     
    Last edited: Jun 25, 2012
  6. Mellbreak

    Mellbreak New Member

    Joined:
    May 8, 2012
    Messages:
    5
    Likes:
    0
    jjw,

    Thanks for the reply. I've come to the conclusion that Oshonsoft BASIC is not really up to the job that I need it to do. Hopefully though your efforts will be of some use to others.

    Best regards,

    Mellbreak
     

Share This Page