ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
notzmv has joined #crystal-lang
ur5us has quit [Ping timeout: 256 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
Flipez has quit [Quit: Ping timeout (120 seconds)]
Flipez has joined #crystal-lang
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
walez has joined #crystal-lang
walez___ has joined #crystal-lang
walez has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 260 seconds]
ua_ has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
jhass[m] has quit [Quit: Bridge terminating on SIGTERM]
jhass[m] has joined #crystal-lang
ua_ has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
jmdaemon has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
Guest30 has joined #crystal-lang
<Guest30> Hi guys, I want to ask a stupid Math question, the result of t = (1 << 64) - (1 << 13) - 1 in Go is 18446744073709543486 (UInt64), but in Crystal it is -8192 (Int32), how should I solve this problem? Thanks a lot!
<Guest30> (1 << 64) - (1 << 13) - 1
<FromGitter> <Blacksmoke16> you just wanting UInt64 max value or?
<Guest30> @Blacksmoke16 Hi, I want to get the same result of Go const RejectAfterMessages.
<FromGitter> <moe:busyloop.net> hm, when you force it to u64, it gives me Arithmetic overflow
<FromGitter> <moe:busyloop.net> does go have no overflow checking? 🤔
<FromGitter> <Blacksmoke16> making them `_u128` works but is off by 63
<FromGitter> <moe:busyloop.net> but as smoke said, if you just want `UInt64::MAX` then that gives you exactly that
Guest3050 has joined #crystal-lang
<Guest3050> BITS_PER_LONG = 64; COUNTER_BITS_TOTAL = 8192; COUNTER_REDUNDANT_BITS = BITS_PER_LONG; COUNTER_WINDOW_SIZE = COUNTER_BITS_TOTAL - COUNTER_REDUNDANT_BITS; REJECT_AFTER_MESSAGES = UInt64::MAX - COUNTER_WINDOW_SIZE - 1_u64
<Guest3050> Another method can be obtained, but I prefer the shift operation. :)
<FromGitter> <moe:busyloop.net> i'm sure there is a plausible explanation for that (but that would have to come from someone way smarter than me) 🤔
alexherbo2 has joined #crystal-lang
Guest30 has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> yea not sure
<FromGitter> <moe:busyloop.net> guest3050, that go-code seems to rely on an integer overflow. maybe that's normal practice in go, but feels rather questionable to me.
<FromGitter> <Blacksmoke16> could also just hard code the value and call it a day
<FromGitter> <moe:busyloop.net> why hardcode when we already have a const exactly for that 🤷
<FromGitter> <Blacksmoke16> just to ensure its the exact same value as Go. seems to also be off a bit so might have some other meaning :shrug:
<FromGitter> <moe:busyloop.net> ah, good point indeed
Guest30 has joined #crystal-lang
<Guest30> @Blacksmoke16 @moe:busyloop.net ok, thank you for your answer, thank you for yours help :)
Guest30 has quit [Client Quit]
<FromGitter> <moe:busyloop.net> reminds me of my fun with json parsers, which randomly mutilate large numbers depending on how the library author felt that day. ⏎ (some truncate to 53 bits, some to 64 bits, some not at all)
Guest3050 has quit [Ping timeout: 260 seconds]
Guest30 has joined #crystal-lang
<FromGitter> <moe:busyloop.net> why would you specify exact number-boundaries in the most used data-transport format anyway - as if anyone cares about such details 🤷
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
Guest3010 has joined #crystal-lang
<Guest3010> @moe: busyloop.net sounds like fun! :) I'm making a WireGuard like thing and I'm trying to figure out, https://github.com/torvalds/linux/blob/master/drivers/net/wireguard/messages.h#L42 https://github.com/WireGuard/wireguard-go/blob/master/device/constants.go#L16
<FromGitter> <RespiteSage> @Guest30 If you just want arithmetic with overflow, you can use `&-`. But the result is still off by 63, like Blacksmoke said: https://carc.in/#/r/e4aq
<FromGitter> <moe:busyloop.net> why not copy the C-code instead of the Go-code? :)
<FromGitter> <moe:busyloop.net> `REJECT_AFTER_MESSAGES = U64_MAX - COUNTER_WINDOW_SIZE - 1` should translate to crystal 1:1, no overflows needed
<FromGitter> <moe:busyloop.net> `REJECT_AFTER_MESSAGES = UInt64::MAX - COUNTER_WINDOW_SIZE - 1`
Guest30 has quit [Ping timeout: 260 seconds]
<Guest3010> Ok, thanks a lot Benjamin Wade @RespiteSage let me learn more \O/ , @moe:busyloop.net Haha yes, but I prefer one line of code.
<Guest3010> Bye, have a good day:)   =*  (y)
Guest3010 has quit [Quit: Client closed]
<FromGitter> <moe:busyloop.net> same :)
alexherbo2 has quit [Ping timeout: 260 seconds]
notzmv has quit [Remote host closed the connection]
walez___ has quit [Quit: Leaving]
<FromGitter> <naqvis> > *<Guest30>* Hi guys, I want to ask a stupid Math question, the result of t = (1 << 64) - (1 << 13) - 1 in Go is 18446744073709543486 (UInt64), but in Crystal it is -8192 (Int32), how should I solve this problem? Thanks a lot! ⏎ ⏎ that's not correct statement. Golang generated untyped int has same value with what you get from Crystal. Both yields `18446744073709543423` ⏎ ⏎ Go Playground:
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
walez has joined #crystal-lang
walez has quit [Quit: Leaving]
_ht has joined #crystal-lang
walez has joined #crystal-lang
acoolstraw has quit [Remote host closed the connection]
acoolstraw has joined #crystal-lang
acoolstraw has quit [Remote host closed the connection]
acoolstraw has joined #crystal-lang
alexherbo2 has joined #crystal-lang
<Ober> ~
<Ober> -)0\''''
<Ober> </cat>
ur5us has joined #crystal-lang
Sankalp has quit [Ping timeout: 260 seconds]
Sankalp has joined #crystal-lang
walez has quit [Quit: Leaving]
<SamantazFox_> naqvis: this is because `x << n` will return 0 if `n` is greater or equal to the number of bits in `x`
<SamantazFox_> you need to specifiy that your 1st integer (which is shifted left by 64) is an int 128, then the compiler will determine that the whole equation results in an int 128
SamantazFox_ is now known as SamantazFox
alexherbo2 has quit [Remote host closed the connection]
_ht has quit [Remote host closed the connection]
<SamantazFox> naqvis Damn sorry, I realized that you were replying to a guest...
<SamantazFox> I hate how it looks like on the IRC side
jmdaemon has joined #crystal-lang
oprypin_ has joined #crystal-lang
lanodan_ has joined #crystal-lang
dostoyev1ky2 has joined #crystal-lang
repo1 has joined #crystal-lang
jhass[m] has quit [*.net *.split]
oprypin has quit [*.net *.split]
lanodan has quit [*.net *.split]
repo has quit [*.net *.split]
dostoyevsky2 has quit [*.net *.split]
dostoyev1ky2 has quit [Quit: leaving]
dostoyevsky2 has joined #crystal-lang
jhass[m] has joined #crystal-lang