Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Next thinBasic: how numeric tokens are stored internally

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Next thinBasic: how numeric tokens are stored internally

    In next thinBasic release, all numbers specified inside a script, will be stored as DOUBLE instead of EXTENDED numbers.

    Example:

    DIM MyVar AS LONG
    MyVar = 1

    thinBasic store "1" as a numeric EXTENDED value in an internal structure in order to be faster the next time the same token is parsed.
    Storing as DOUBLE seems a little advantage (10 bytes EXT against 8 bytes DOUBLE) but when numbers are inside loops (and it happens a lot of times) it can be a signficative improve. Also I've not seen any script so far that requiires to store a numeric value with the magnitude of EXT numeric data.

    Do you see any problems?

    Thanks a lot
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2

    Re: Next thinBasic: how numeric tokens are stored internally

    Eros:

    Will all internal numerical calculations still be performed in EXTENDED?

    If not, will the use of EXTENDED still be available, as an option, for performing calculations at higher precision?

    Don
    XPS 1710

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Next thinBasic: how numeric tokens are stored internally

    I am with Don,

    it would be nice to have EXT variable when declared AS EXT, for the rest DOUBLE is ok.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Next thinBasic: how numeric tokens are stored internally

    Yes, all internal calculation are always performed at the maximum precision, that is EXTENDED.

    The change will only influence how the "clear text" numbers indicated in the scripts are stored and not how they are used for calculation.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5

    Re: Next thinBasic: how numeric tokens are stored internally

    Eros:

    I am not clear yet regarding how inputted and/or computed numerical variables can be stored under your proposed change.

    For example, will it be possible to specifically declare a variable (either inputted or computed in the program) as EXTENDED so that it is stored in the program as EXTENDED?

    I particular, I am concerned about loosing computed precision if EXTENDED computed values are temporarily stored in program variables unless these program variables are also EXTENDED. For example, obital calculations frequently require high precision temporary storage between computational steps; otherwise the computed precision is lost if the computations are stored in variables of lesser significance.

    Don
    XPS 1710

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Next thinBasic: how numeric tokens are stored internally

    Quote Originally Posted by GSAC3
    I am not clear yet regarding how inputted and/or computed numerical variables can be stored under your proposed change.
    Hi Don,

    here I'm not referring to "variables" but to numbers present in source script. There will not be any loosing precision in any calculation. Variables will be stored and handled with the precision of the type used when variables are declared (LONG, DOUBLE, EXT, ... whatever). All internal intermediate calculations are always done with the highest precision avaliable in thinBasic, that is EXTENDED. And this will continue.

    New way of handling "source code numbers" has just to do the parsing process not calculations during execution. When thinBasic loads a source code, a big part is parsing every source tokens. Every token is than stored and optimized in internal data structures in order to be fast to retrieve them when needed. One of those token class is "numbers", all the numbers present in source code: 1, 10000, 0.0003, 1234.567890123, ... whatever. Those numbers are not parsed every time but are stored in temp areas. Currently those areas are dimensioned as 10 bytes with EXTENDED precision. In new version those numbers will be stored in 8 bytes with DOUBLE precision. DOUBLE precision has a range from 4.19x10^-307 and 1.79x10^308 (see thinBasic help at http://www.thinbasic.com/public/prod...cvariables.htm ) so enough for whatever number I've seen in any script so far.

    Hope to have cleared the doubts, otherwise ask again or please provide a piece of source code example to check and I will make tests.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7

    Re: Next thinBasic: how numeric tokens are stored internally

    Eros:

    Thank you for your clarification. I understand what you are proposing now.

    Don
    XPS 1710

  8. #8

    Re: Next thinBasic: how numeric tokens are stored internally

    Eros:

    If I understand you correctly, the following syntax would no longer store the two 18 significant figure values under your proposed change.

    DIM DR AS EXT VALUE = 0.0174532925199432957 '18 significant digits
    DIM RD AS EXT VALUE = 57.2957795130823209 '18 significant digits

    Instead, only the first 16 significant figures would be stored in the two variables.

    Don
    XPS 1710

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Next thinBasic: how numeric tokens are stored internally

    Result will be the following:
    [code=thinbasic]
    uses "CONSOLE"

    DIM DR AS EXT VALUE = 0.0174532925199432957 '18 significant digits
    DIM RD AS EXT VALUE = 57.2957795130823209 '18 significant digits

    printl "DR=" & str$(DR, 1
    printl "RD=" & str$(RD, 1
    waitkey

    '---Output:
    'DR= 1.74532925199432957E-2
    'RD= 57.2957795130823209
    [/code]

    Are you using those kind of figures? What do you use thinBasic for?

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Next thinBasic: how numeric tokens are stored internally

    Stupid question mine :-[

    [code=thinbasic]
    uses "CONSOLE"

    printl "Radians(180)=" & radians(180)
    printl "Degrees(Radians(180))=" & Degrees(Radians(180))
    waitkey


    function radians(deg as ext) as ext
    function = deg * .0174532925199432957
    end function

    function degrees(rad as ext) as ext
    function = rad * 57.29577951308232103
    end function
    [/code]

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 1 of 2 12 LastLast

Similar Threads

  1. New in next thinBasic: numeric type casting
    By ErosOlmi in forum thinBasic vaporware
    Replies: 9
    Last Post: 18-07-2008, 21:11

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •