bits

package main
import (
*"fmt"*
*"math"*
)
func main() {
negative := -10
fmt.Println(negative)
*// Use math.Abs to convert to a positive number.*
*// ... We first convert to a float64.*
result := math.Abs(float64(negative))
fmt.Println(result)
}-10
10

package main
import (
*"fmt"*
*"math"*
)
func main() {
*// This can handle ints.*
result := math.Pow(2, 3)
fmt.Println(result)
}8

package main
import (
*"fmt"*
*"math"*
)
func main() {
small := float64(3)
large := float64(40)
*// Get the larger of the two numbers.*
max := math.Max(small, large)
fmt.Println(max)
*// Get the smaller value.*
min := math.Min(small, large)
fmt.Println(min)
}40
3

package main
import (
*"fmt"*
*"math"*
)
func main() {
value1 := 1.23
fmt.Println(value1)
fmt.Println(math.Floor(value1))
value2 := 2.99
fmt.Println(value2)
fmt.Println(math.Floor(value2))
value3 := -1.1
fmt.Println(value3)
fmt.Println(math.Floor(value3))
}1.23
1
2.99
2
-1.1
-2

package main
import (
*"fmt"*
*"math"*
)
func main() {
value1 := float64(1)
negative := math.Signbit(value1)
fmt.Println(negative)
value2 := float64(-1)
negative = math.Signbit(value2)
fmt.Println(negative)
value3 := float64(0)
negative = math.Signbit(value3)
fmt.Println(negative)
}false
true
false

Odd, Even

Fibonacci

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Dec 4, 2021 (edit link).