Author Topic: big number  (Read 1301 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaze

  • Newbie
  • Posts: 86
big number
« on: April 04, 2022, 05:49:49 pm »
is there a way to use and integer value bigger than the LONG data type allows?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: big number
« Reply #1 on: April 04, 2022, 06:17:57 pm »
Yes, Type _Integer64

and if all positive or 0 then use _unsigned _integer64

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
Re: big number
« Reply #2 on: April 04, 2022, 06:34:09 pm »
hello Jaze
an unsigned integer64 can hold up-to 18446744073709551615 if you want numbers bigger than that I woul suggest LibTomMath from https://www.libtom.net/ let me know if that's what you want

Offline Jaze

  • Newbie
  • Posts: 86
Re: big number
« Reply #3 on: April 04, 2022, 09:24:47 pm »
thank you so much.  I'm working on a time calculator with precision to the second and trying to convert years to seconds. A LONG doesn't allow more than 10 years or so. Thanks again

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: big number
« Reply #4 on: April 05, 2022, 12:33:53 am »
thank you so much.  I'm working on a time calculator with precision to the second and trying to convert years to seconds. A LONG doesn't allow more than 10 years or so. Thanks again

Code: QB64: [Select]
  1.  
  2. FUNCTION TimeStamp## (d$, t##) 'date and timer
  3.     'Based on Unix Epoch time, which starts at year 1970.
  4.     DIM s AS _FLOAT
  5.  
  6.     l = INSTR(d$, "-")
  7.     l1 = INSTR(l + 1, d$, "-")
  8.     m = VAL(LEFT$(d$, l))
  9.     d = VAL(MID$(d$, l + 1))
  10.     y = VAL(MID$(d$, l1 + 1))
  11.     IF y < 1970 THEN 'calculate shit backwards
  12.         SELECT CASE m 'turn the day backwards for the month
  13.             CASE 1, 3, 5, 7, 8, 10, 12: d = 31 - d '31 days
  14.             CASE 2: d = 28 - d 'special 28 or 29.
  15.             CASE 4, 6, 9, 11: d = 30 - d '30 days
  16.         END SELECT
  17.         IF y MOD 4 = 0 AND m < 3 THEN 'check for normal leap year, and we're before it...
  18.             d = d + 1 'assume we had a leap year, subtract another day
  19.             IF y MOD 100 = 0 AND y MOD 400 <> 0 THEN d = d - 1 'not a leap year if year is divisible by 100 and not 400
  20.         END IF
  21.  
  22.         'then count the months that passed after the current month
  23.         FOR i = m + 1 TO 12
  24.             SELECT CASE i
  25.                 CASE 2: d = d + 28
  26.                 CASE 3, 5, 7, 8, 10, 12: d = d + 31
  27.                 CASE 4, 6, 9, 11: d = d + 30
  28.             END SELECT
  29.         NEXT
  30.  
  31.         'we should now have the entered year calculated.  Now lets add in for each year from this point to 1970
  32.         d = d + 365 * (1969 - y) '365 days per each standard year
  33.         FOR i = 1968 TO y + 1 STEP -4 'from 1968 onwards,backwards, skipping the current year (which we handled previously in the FOR loop)
  34.             d = d + 1 'subtract an extra day every leap year
  35.             IF (i MOD 100) = 0 AND (i MOD 400) <> 0 THEN d = d - 1 'but skipping every year divisible by 100, but not 400
  36.         NEXT
  37.         s## = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
  38.         TimeStamp## = -(s## + 24 * 60 * 60 - t##)
  39.         EXIT FUNCTION
  40.     ELSE
  41.         y = y - 1970
  42.     END IF
  43.  
  44.     FOR i = 1 TO m 'for this year,
  45.         SELECT CASE i 'Add the number of days for each previous month passed
  46.             CASE 1: d = d 'January doestn't have any carry over days.
  47.             CASE 2, 4, 6, 8, 9, 11: d = d + 31
  48.             CASE 3 'Feb might be a leap year
  49.                 IF (y MOD 4) = 2 THEN 'if this year is divisible by 4 (starting in 1972)
  50.                     d = d + 29 'its a leap year
  51.                     IF (y MOD 100) = 30 AND (y MOD 400) <> 30 THEN 'unless..
  52.                         d = d - 1 'the year is divisible by 100, and not divisible by 400
  53.                     END IF
  54.                 ELSE 'year not divisible by 4, no worries
  55.                     d = d + 28
  56.                 END IF
  57.             CASE 5, 7, 10, 12: d = d + 30
  58.         END SELECT
  59.     NEXT
  60.     d = (d - 1) + 365 * y 'current month days passed + 365 days per each standard year
  61.     FOR i = 2 TO y - 1 STEP 4 'from 1972 onwards, skipping the current year (which we handled previously in the FOR loopp)
  62.         d = d + 1 'add an extra day every leap year
  63.         IF (i MOD 100) = 30 AND (i MOD 400) <> 30 THEN d = d - 1 'but skiping every year divisible by 100, but not 400
  64.     NEXT
  65.     s## = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
  66.     TimeStamp## = (s## + t##)
  67.  

Pass it a date and timer and it calculates a timestamp for use.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: big number
« Reply #5 on: April 06, 2022, 06:35:54 am »
@Jaze It's always worth checking the QB64 Wiki Pages https://wiki.qb64.org/, and in this case there is a Wiki page on Variable Types https://wiki.qb64.org/wiki/Variable_Types


Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: big number
« Reply #6 on: April 06, 2022, 01:41:54 pm »
@Jaze It's always worth checking the QB64 Wiki Pages https://wiki.qb64.org/, and in this case there is a Wiki page on Variable Types https://wiki.qb64.org/wiki/Variable_Types

Yes, that page is a keeper. I use it fairly frequently. I miss the days my mind worked like a computer, and I didn't need a cheat sheet. On the bright side, I don't miss typing on my eyeballs to get that information. Bill, I wrote eyeballs, Bill. Leave it alone!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/