Created
December 21, 2015 07:15
-
-
Save nilz3ro/38ed8d4d0c42e112c0be to your computer and use it in GitHub Desktop.
Wondering what the maximum integer value is in the go language? Wonder no more!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
const ( | |
MaxInt8 = 1<<7 - 1 // 127 | |
MinInt8 = -1 << 7 | |
MaxInt16 = 1<<15 - 1 // 32_767 | |
MinInt16 = -1 << 15 | |
MaxInt32 = 1<<31 - 1 // 2_147_483_647 | |
MinInt32 = -1 << 31 | |
MaxInt64 = 1<<63 - 1 | |
MinInt64 = -1 << 63 | |
MaxUint8 = 1<<8 - 1 | |
MaxUint16 = 1<<16 - 1 | |
MaxUint32 = 1<<32 - 1 | |
MaxUint64 = 1<<64 - 1 | |
) | |
func factorial(number int) int { | |
maximum := MaxInt32; | |
if number >= maximum { | |
fmt.Println("Int too large to compute!!", number, maximum); | |
panic("Int too large to compute!!"); | |
return 1; | |
} else if number == 0 { | |
fmt.Println("Terminal case reached, returning!"); | |
return 1; | |
} else { | |
return number * factorial(number-1); | |
} | |
} | |
func main() { | |
var total int; | |
total = factorial(2147483); | |
fmt.Println(total); | |
fmt.Println("TUST"); | |
defer fmt.Println(total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment