aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-03-29 00:09:46 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-03-29 00:09:46 +0100
commitc6194ac91c02773d6b4ffbd53b2735f3ec6199cc (patch)
tree68ed08eddd6503d78dfe8dc3ea2b9373b99dbaf5
parent9269498702e0ede86aa48451e642921fdfd5a486 (diff)
Add IsType() functions
-rw-r--r--format.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/format.go b/format.go
index b1a939c..d635be9 100644
--- a/format.go
+++ b/format.go
@@ -1,6 +1,9 @@
package main
-import "fmt"
+import (
+ "fmt"
+ "math"
+)
type S string // string
type I int64 // int
@@ -35,3 +38,15 @@ func (f F) String() string {
func (c C) String() string {
return fmt.Sprint(F(real(c)), "J", F(imag(c)))
}
+
+func IsInt(c complex128) bool {
+ return imag(c) == 0 && math.Trunc(real(c)) == real(c)
+}
+
+func IsFloat(c complex128) bool {
+ return imag(c) == 0 && math.Trunc(real(c)) != real(c)
+}
+
+func IsComplex(c complex128) bool {
+ return imag(c) != 0
+}