# Adding to Long Infinity in kdb? - Kdb+ / qStudio

Home Forums Kdb+ / qStudio Adding to Long Infinity in kdb?

Tagged:

This topic contains 1 reply, has 2 voices, and was last updated by  matt 5 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
• Author
Posts
• #111269

I received this question from a student:

What is happening when I add to a long infinty in kdb?

Perhaps someone can answer this one?

#111276

matt
Member

Short answer: Assuming that it is a positive number, then it would overflow (and most likely end up as a negative value).

Long answer: kdb+ represents infinity as the largest positive integer (in 2’s complement) of that datatype. So for long (64 bits) that would be 2^63-1. This can easily be verified:
`
0W – 1 = 0111 1111 1111 … 1110 =  2^63-2 = 9223372036854775806
0W     = 0111 1111 1111 … 1111 =  2^63-1 = 0W
0W + 1 = 1000 0000 0000 … 0000 = -2^63   = 0N
0W + 2 = 1000 0000 0000 … 0001 = -2^63+1 = -0W
0W + 3 = 1000 0000 0000 … 0010 = -2^63+2 = -9223372036854775806
`

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.