From: Nicolas Peugnet <nicolas@club1.fr>
Date: Mon, 1 Sep 2025 11:12:36 +0200
Subject: Do not use reflect to check if Number is float

This allows to get rid of the reflect dependencies and also makes the
code run a bit faster.

Before:
	$ go test -bench=.
	goos: linux
	goarch: amd64
	pkg: fortio.org/safecast
	cpu: 13th Gen Intel(R) Core(TM) i9-13900
	BenchmarkMustConvert_float64_int8-32    	560162847	         2.004 ns/op
	BenchmarkMustConvert_int_int8-32        	738659530	         1.619 ns/op
	PASS
	ok  	fortio.org/safecast	2.322s

After:
	$ go test -bench=.
	goos: linux
	goarch: amd64
	pkg: fortio.org/safecast
	cpu: 13th Gen Intel(R) Core(TM) i9-13900
	BenchmarkMustConvert_float64_int8-32    	597861529	         1.844 ns/op
	BenchmarkMustConvert_int_int8-32        	831054811	         1.438 ns/op
	PASS
	ok  	fortio.org/safecast	2.304s
---
 safecast.go      |  5 ++---
 safecast_test.go | 12 ++++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/safecast.go b/safecast.go
index cf5a34d..32f6411 100644
--- a/safecast.go
+++ b/safecast.go
@@ -10,7 +10,6 @@ import (
 	"errors"
 	"fmt"
 	"math"
-	"reflect"
 	"unsafe"
 )
 
@@ -35,8 +34,8 @@ const (
 )
 
 func isFloat[Num Number](f Num) (isFloat bool) {
-	switch reflect.TypeOf(f).Kind() { //nolint:exhaustive // only 2 we want to check
-	case reflect.Float32, reflect.Float64:
+	switch any(f).(type) { //nolint:exhaustive // only 2 we want to check
+	case float32, float64:
 		isFloat = true
 	}
 	return
diff --git a/safecast_test.go b/safecast_test.go
index 2bea458..e7d8f19 100644
--- a/safecast_test.go
+++ b/safecast_test.go
@@ -427,3 +427,15 @@ func ExampleMustRound() {
 	fmt.Println("not reached", out) // not reached
 	// Output: panic: safecast: out of range for -128.6 (float64) to int8
 }
+
+func BenchmarkMustConvert_float64_int8(b *testing.B) {
+	for b.Loop() {
+		safecast.MustConvert[int8](1.0)
+	}
+}
+
+func BenchmarkMustConvert_int_int8(b *testing.B) {
+	for b.Loop() {
+		safecast.MustConvert[int8](1)
+	}
+}
