Results 1 to 4 of 4

Thread: how to store (and do arithmetic) and recall/display unsigned 64-bit (8-byte) integer?

  1. #1
    Member DirectuX's Avatar
    Join Date
    Oct 2018
    Location
    France
    Posts
    417
    Rep Power
    55

    Question how to store (and do arithmetic) and recall/display unsigned 64-bit (8-byte) integer?

    Hi,
    how to store (and do arithmetic) and recall/display unsigned 64-bit (8-byte) integer?
    according to msdn it's 0 to 18,446,744,073,709,551,615
    alias uint64 windows data type
    how do you do this in thinBasic ?

    Quote Originally Posted by from thinBasic's help;
    Internally, a VARIANT is always 16-bytes in size
    %VT_R8 Double
    %VT_UI8 Quad (unsigned)
    Is this info contradictory ? I didn't understand it.


    I wrote this code numeric.zip to experiment data types , variant in particular,
    there's even one case where the variant return value is different from input:

    uses "console"
    
    ' how to store (and do arithmetic) and recall/display unsigned 64-bit (8-byte) integer?
    ' 0 to 18,446,744,073,709,551,615
    ' alias uint64 windows data type
    
    'From thinbasic help :
    
    'Internally, a VARIANT is always 16-bytes in size
    '       %VT_R8           Double
    '       %VT_UI8          Quad (unsigned)
    
    Dim var_01 as Number value = 876543210987654321
    Dim var_02 as Ext value = 876543210987654321
    dim var_03 as Quad value = 876543210987654321
    dim var_04 as Variant value = 876543210987654321
    
    const Digits value = 18' Specifies the maximum number of significant digits (1 to 18) desired in the result.
    
    Printl "For the value 876543210987654321 which is 18 significant digits," & $crlf & "it seems to be the limit with str$"
    printl ""
    
    display(str$(var_01,Digits),"Dim var_01 as Number")
    display(str$(var_02,Digits),"Dim var_02 as Ext")
    display(str$(var_03,Digits),"Dim var_03 as Quad")
    
    printl ""
    printl string$(20,"*") & "press a key to continue" & string$(20,"*") 
    printl ""
    waitkey
    
    printl ""
    printl "Internally, a VARIANT is always 16-bytes in size"
    printl "%VT_R8     means      Double"
    printl "%VT_UI8    means      Quad (unsigned)"
    printl ""
    
    display(str$(var_04,Digits),"dim var_04 as Variant" & " displayed via str$," & $crlf & "internally stored as " & VARIANTVT$(var_04) & "   !!! Notice value change !!!")
    display(VARIANT$(var_04),"dim var_04 as Variant" & " displayed via VARIANT$," & $crlf & "internally stored as " & VARIANTVT$(var_04))
    display(var_04,"dim var_04 as Variant" & " displayed directly," & $crlf & "internally stored as " & VARIANTVT$(var_04))
    
    printl ""
    printl ""
    printl ""
    
    printl ""
    printl string$(20,"*") & "press a key to continue" & string$(20,"*") 
    printl ""
    waitkey
    
    Printl "For the value 18446744073709551615 which is 20 significant digits," & $crlf & "the maximum number for uint64 according to msdn"
    printl ""
    
    Dim var_05 as Number value = 18446744073709551615
    Dim var_06 as Ext value = 18446744073709551615
    dim var_07 as Quad value = 18446744073709551615
    dim var_08 as Variant value = 18446744073709551615
    
    display(str$(var_05,Digits),"Dim var_05 as Number")
    display(str$(var_06,Digits),"Dim var_06 as Ext")
    display(str$(var_07,Digits),"Dim var_07 as Quad")
    
    printl ""
    printl string$(20,"*") & "press a key to continue" & string$(20,"*") 
    printl ""
    waitkey
    
    display(str$(var_08,Digits),"dim var_08 as Variant" & " displayed via str$," & $crlf & "internally stored as " & VARIANTVT$(var_04))
    display(VARIANT$(var_08),"dim var_08 as Variant" & " displayed via VARIANT$," & $crlf & "internally stored as " & VARIANTVT$(var_04))
    display(var_08,"dim var_08 as Variant" & " displayed directly," & $crlf & "internally stored as " & VARIANTVT$(var_04))
    
    function display(what as string, varname as string)
      printl (string$(30,"-"))
      printl ("  " & varname)
      Printl "string = " & what
      Printl "length = " & len(what)
    end function
    
    printl ""
    printl string$(20,"*") & "press a key to exit" & string$(20,"*") 
    printl ""
    waitkey
    
    I can't achieve to make a variant store data as %VT_UI8 .

    Help ?
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  2. #2
    Member DirectuX's Avatar
    Join Date
    Oct 2018
    Location
    France
    Posts
    417
    Rep Power
    55

    Lightbulb

    Meanwhile on thinBasic,
    I've found this https://www.thinbasic.com/community/...latest-release, but this is overkill.
    How an 8-byte integer can't be hold by a 16-byte variant ?

    any info about %VT_UI8 Quad (unsigned) ?
    Last edited by DirectuX; 22-11-2018 at 21:18.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

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

    ThinBASIC currently supports just signed 64bit integers, their range should be -9.22x10^18 - 9.22x10^18.

    May I ask for your use case for such a huge numbers? Just curious.


    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
    Member DirectuX's Avatar
    Join Date
    Oct 2018
    Location
    France
    Posts
    417
    Rep Power
    55

    Smile

    Quote Originally Posted by Petr Schreiber View Post

    ThinBASIC currently supports just signed 64bit integers
    but 16-byte variant ? It doesn't fit in my logic.

    Quote Originally Posted by Petr Schreiber View Post

    their range should be -9.22x10^18 - 9.22x10^18.
    I'm not comfortable enough to think out a workaround by myself right now, do you know one ?

    Quote Originally Posted by Petr Schreiber View Post

    May I ask for your use case for such a huge numbers? Just curious.
    Sure, and the useful answer is here:

    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx ; Originally Eros Olmi provided this link.

    More personal answer : I'm writing a utility program for which i should compute informations about disks; Several properties are provided by Windows as uint64.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Similar Threads

  1. Microsoft Windows Store
    By ErosOlmi in forum Development
    Replies: 4
    Last Post: 08-12-2011, 21:16
  2. byte example + udt
    By Lionheart008 in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 4
    Last Post: 30-01-2010, 13:40
  3. Arithmetic
    By Charles Pegge in forum O2h Compiler
    Replies: 0
    Last Post: 17-03-2009, 15:27
  4. Arithmetic on the FPU: (vv1+vv2) / (vv3+vv4)
    By Charles Pegge in forum Machine Code: script sources and examples
    Replies: 3
    Last Post: 10-03-2008, 22:43
  5. Config parameters: where to store them?
    By ErosOlmi in forum thinAir General
    Replies: 5
    Last Post: 31-05-2006, 08:21

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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