What's the type?

Report a typo

You already know that every int type in Go has a range with possible values for this type. Check what types of int values we can use for a given number from:

  • uint8
  • uint16
  • uint32
  • uint64

If our source value is greater than all the types, please print “unsupported type” instead.

Sample Input 1:

42

Sample Output 1:

uint8
uint16
uint32
uint64
Write a program in Go
package main

import "fmt"

const (
MaxUint8 = 1<<8 - 1
MaxUint16 = 1<<16 - 1
MaxUint32 = 1<<32 - 1
MaxUint64 = 1<<64 - 1
)

func main() {
var source float64
fmt.Scan(&source)

// check if the source value can be converted to int8 value without overflow
if source < float64(MaxUint8) {
fmt.Println("uint8")
}

// add the same check for 16, 32, 64 bits...

// check if the source value is out of the range for all types
if float64(?) < source {
fmt.Println("unsupported type")
}
}
___

Create a free account to access the full topic