Skip to content

Instantly share code, notes, and snippets.

@intsuc
Last active July 26, 2024 12:14
Show Gist options
  • Save intsuc/4f5adc77156fbe054362ea1f75a7864c to your computer and use it in GitHub Desktop.
Save intsuc/4f5adc77156fbe054362ea1f75a7864c to your computer and use it in GitHub Desktop.
Convert a long tag into high and low 32-bit integers and vice versa
function init
# 1782934792843521910 = 0x18be41bf_691f6f76
# = (0x18be41bf, 0x691f6f76)
# = (415121855, 1763667830)
data modify storage _ source set value 1782934792843521910L
# 1782934792843521910 -> (415121855, 1763667830)
function split
# #a[63:32] has 415121855 [_]
scoreboard players get #a[63:32] _
# #a[31:00] has 1763667830 [_]
scoreboard players get #a[31:00] _
# (415121855, 1763667830) -> 1782934792843521910
function merge
# Storage minecraft:_ has the following contents: 1782934792843521910L
data get storage _ result
# -7391011204884992123 = 0x996dda77_e9e5ef85
# = (0x996dda77, 0xe9e5ef85)
# = (-1720853897, -370806907)
data modify storage _ source set value -7391011204884992123L
# -7391011204884992123 -> (-1720853897, -370806907)
function split
# #a[63:32] has -1720853897 [_]
scoreboard players get #a[63:32] _
# #a[31:00] has -370806907 [_]
scoreboard players get #a[31:00] _
# (-1720853897, -370806907) -> -7391011204884992123
function merge
# Storage minecraft:_ has the following contents: -7391011204884992123L
data get storage _ result
# a = a - c
# = a - (a % 10)
scoreboard players operation #a[31:00] _ += #-2147483648 _
scoreboard players operation #c _ += #-2147483648 _
execute if score #a[31:00] _ < #c _ run scoreboard players remove #a[63:32] _ 1
scoreboard players operation #a[31:00] _ += #-2147483648 _
scoreboard players operation #c _ += #-2147483648 _
scoreboard players operation #a[31:00] _ -= #c _
# a = a / 5
# = a * 0xcccccccccccccccd
function mul_cccccccccccccccd
# a = a / 2
# = a >> 1
scoreboard players operation #d _ = #a[63:32] _
scoreboard players operation #d _ *= #-2147483648 _
scoreboard players operation #a[63:32] _ /= #2 _
scoreboard players operation #a[31:00] _ /= #2 _
execute if score #a[31:00] _ matches ..-1 run scoreboard players operation #a[31:00] _ += #-2147483648 _
scoreboard players operation #a[31:00] _ += #d _
scoreboard objectives add _ dummy
scoreboard players set #-2147483648 _ -2147483648
scoreboard players set #-859045888 _ -859045888
scoreboard players set #-858980352 _ -858980352
scoreboard players set #-1 _ -1
scoreboard players set #2 _ 2
scoreboard players set #10 _ 10
scoreboard players set #52428 _ 52428
scoreboard players set #52429 _ 52429
scoreboard players set #65536 _ 65536
data modify storage _ wrapper set value [I;0]
$data modify storage _ result set value $(sign)$(18)$(17)$(16)$(15)$(14)$(13)$(12)$(11)$(10)$(9)$(8)$(7)$(6)$(5)$(4)$(3)$(2)$(1)$(0)L
# result = (a.high, a.low)
execute if score #a[63:32] _ matches ..-2147483648 if score #a[31:00] _ matches 0 run return run data modify storage _ result set value -9223372036854775808L
data modify storage _ digits set value { \
0: "", \
1: "", \
2: "", \
3: "", \
4: "", \
5: "", \
6: "", \
7: "", \
8: "", \
9: "", \
10: "", \
11: "", \
12: "", \
13: "", \
14: "", \
15: "", \
16: "", \
17: "", \
18: "", \
sign: "", \
}
execute if score #a[63:32] _ matches ..-1 run function neg
function to_digits
function join_digits with storage _ digits
data remove storage _ digits
# a = a * 0xcccccccccccccccd
scoreboard players operation #a[15:00] _ = #a[31:00] _
scoreboard players operation #a[15:00] _ %= #65536 _
scoreboard players operation #a[31:16] _ = #a[31:00] _
scoreboard players operation #a[31:16] _ /= #65536 _
execute if score #a[31:16] _ matches ..-1 run scoreboard players add #a[31:16] _ 65536
scoreboard players operation #a[47:32] _ = #a[63:32] _
scoreboard players operation #a[47:32] _ %= #65536 _
scoreboard players operation #a[63:48] _ = #a[63:32] _
scoreboard players operation #a[63:48] _ /= #65536 _
execute if score #a[63:48] _ matches ..-1 run scoreboard players add #a[63:48] _ 65536
scoreboard players operation #a[15:00]+a[31:16] _ = #a[15:00] _
scoreboard players operation #a[15:00]+a[31:16] _ += #a[31:16] _
scoreboard players operation #d _ = #a[15:00] _
scoreboard players operation #d _ *= #52428 _
scoreboard players operation #d _ /= #65536 _
execute if score #d _ matches ..-1 run scoreboard players add #d _ 65536
scoreboard players operation #a[63:32] _ = #d _
scoreboard players operation #d _ = #a[31:16] _
scoreboard players operation #d _ *= #52429 _
scoreboard players operation #d _ /= #65536 _
execute if score #d _ matches ..-1 run scoreboard players add #d _ 65536
scoreboard players operation #a[63:32] _ += #d _
scoreboard players operation #d _ = #a[15:00]+a[31:16] _
scoreboard players operation #d _ *= #52428 _
scoreboard players operation #a[63:32] _ += #d _
scoreboard players operation #d _ = #a[47:32] _
scoreboard players operation #d _ *= #52429 _
scoreboard players operation #a[63:32] _ += #d _
scoreboard players operation #d _ = #a[15:00]+a[31:16] _
scoreboard players operation #d _ += #a[47:32] _
scoreboard players operation #d _ *= #-859045888 _
scoreboard players operation #a[63:32] _ += #d _
scoreboard players operation #d _ = #a[63:48] _
scoreboard players operation #d _ *= #-858980352 _
scoreboard players operation #a[63:32] _ += #d _
scoreboard players operation #d _ = #a[15:00] _
scoreboard players operation #d _ *= #52429 _
scoreboard players operation #a[31:00] _ = #d _
scoreboard players operation #d _ = #a[15:00] _
scoreboard players operation #d _ *= #-859045888 _
scoreboard players operation #a[31:00] _ += #d _
scoreboard players operation #a[31:00] _ += #-2147483648 _
scoreboard players operation #d _ += #-2147483648 _
execute if score #a[31:00] _ < #d _ run scoreboard players add #a[63:32] _ 1
scoreboard players operation #a[31:00] _ += #-2147483648 _
scoreboard players operation #d _ = #a[31:16] _
scoreboard players operation #d _ *= #-858980352 _
scoreboard players operation #a[31:00] _ += #d _
scoreboard players operation #a[31:00] _ += #-2147483648 _
scoreboard players operation #d _ += #-2147483648 _
execute if score #a[31:00] _ < #d _ run scoreboard players add #a[63:32] _ 1
scoreboard players operation #a[31:00] _ += #-2147483648 _
# a = a * -1
# = 0 - a
scoreboard players operation #a[63:32] _ *= #-1 _
scoreboard players remove #a[63:32] _ 1
scoreboard players operation #a[31:00] _ *= #-1 _
data modify storage _ digits.sign set value -
# return c = a % 10
# low
scoreboard players operation #d _ = #a[31:00] _
execute if score #a[63:32] _ matches 0 store result score #c _ run return run scoreboard players operation #d _ %= #10 _
scoreboard players set #c _ 0
# 2147483648
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 1073741824
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 536870912
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 268435456
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 134217728
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 67108864
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 33554432
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 16777216
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 8388608
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 4194304
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 2097152
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 1048576
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 524288
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 262144
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 131072
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 65536
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 32768
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 16384
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 8192
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 4096
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 2048
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 1024
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 512
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 256
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 128
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 64
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 32
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 16
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 8
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 4
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 2
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 1
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 1
# high
scoreboard players operation #d _ = #a[63:32] _
# 4611686018427387904
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 2305843009213693952
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 1152921504606846976
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 576460752303423488
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 288230376151711744
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 144115188075855872
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 72057594037927936
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 36028797018963968
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 18014398509481984
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 9007199254740992
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 4503599627370496
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 2251799813685248
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 1125899906842624
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 562949953421312
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 281474976710656
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 140737488355328
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 70368744177664
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 35184372088832
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 17592186044416
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 8796093022208
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 4398046511104
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 2199023255552
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 1099511627776
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 549755813888
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 274877906944
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 137438953472
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 68719476736
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
# 34359738368
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 8
# 17179869184
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 4
# 8589934592
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 2
# 4294967296
scoreboard players operation #d _ += #d _
execute if score #d _ matches ..-1 run scoreboard players add #c _ 6
return run scoreboard players operation #c _ %= #10 _
# (a.high, a.low) = source
data modify storage _ wrapper[0] set from storage _ source
execute store result score #a[31:00] _ run data get storage _ wrapper[0] 1
execute store result score #a[63:32] _ run data get storage _ source 0.00000000023283064365386963
execute store result score #c _ run data get storage _ source -0.00000000023283064365386963
scoreboard players operation #d _ = #a[63:32] _
scoreboard players operation #d _ > #c _
execute if score #a[31:00] _ matches 0.. run return 0
execute if score #d _ matches 0..2097151 run return 0
execute if score #a[31:00] _ matches -512.. if score #d _ matches 1073741824..2147483646 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -256.. if score #d _ matches 536870912..1073741823 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -128.. if score #d _ matches 268435456..536870911 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -64.. if score #d _ matches 134217728..268435455 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -32.. if score #d _ matches 67108864..134217727 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -16.. if score #d _ matches 33554432..67108863 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -8.. if score #d _ matches 16777216..33554431 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -4.. if score #d _ matches 8388608..16777215 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -2.. if score #d _ matches 4194304..8388607 run return run scoreboard players remove #a[63:32] _ 1
execute if score #a[31:00] _ matches -1.. if score #d _ matches 2097152..4194303 run return run scoreboard players remove #a[63:32] _ 1
execute if score #d _ matches 2147483647.. if score #a[31:00] _ matches -512.. if score #c _ matches -2147483647.. run scoreboard players remove #a[63:32] _ 1
execute store result storage _ digits.0 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 1
function div_10
execute store result storage _ digits.1 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 2
function div_10
execute store result storage _ digits.2 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 3
function div_10
execute store result storage _ digits.3 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 4
function div_10
execute store result storage _ digits.4 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 5
function div_10
execute store result storage _ digits.5 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 6
function div_10
execute store result storage _ digits.6 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 7
function div_10
execute store result storage _ digits.7 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 8
function div_10
execute store result storage _ digits.8 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 9
function div_10
execute store result storage _ digits.9 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 10
function div_10
execute store result storage _ digits.10 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 11
function div_10
execute store result storage _ digits.11 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 12
function div_10
execute store result storage _ digits.12 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 13
function div_10
execute store result storage _ digits.13 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 14
function div_10
execute store result storage _ digits.14 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 15
function div_10
execute store result storage _ digits.15 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 16
function div_10
execute store result storage _ digits.16 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 17
function div_10
execute store result storage _ digits.17 int 1 run function rem_10
execute if score #a[63:32] _ matches 0 if score #a[31:00] _ matches 0..9 run return 18
function div_10
execute store result storage _ digits.18 int 1 run function rem_10
return 19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment