Skip to content

Instantly share code, notes, and snippets.

@mattfenwick
Created January 29, 2024 15:21
Show Gist options
  • Save mattfenwick/ac50a889b7377b899227c4289e2e78f9 to your computer and use it in GitHub Desktop.
Save mattfenwick/ac50a889b7377b899227c4289e2e78f9 to your computer and use it in GitHub Desktop.
golang vs java

Golang

https://go.dev/play/p/AMM1IEcVyq9

package main

import "fmt"

func main() {
	f32 := float32(17) / float32(33) * float32(99.0)
	f64 := float64(17) / float64(33) * float64(99.0)
	i32 := int(f32)
	i64 := int(f64)
	fmt.Printf("32: %d, %f\n64: %d, %f\n", i32, f32, i64, f64)
}

output:

32: 51, 51.000000
64: 51, 51.000000

Java 11

float f = ((float) 17 / (float) 33 * 99.0);
int i = (int) f;

output:

50.999998569488525
50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment