@@ -54,14 +54,29 @@ extension NSData: ScalarRepresentable {
5454
5555extension NSNumber : ScalarRepresentable {
5656 public func represented( ) -> Node . Scalar {
57- if let value = Bool ( exactly: self ) {
58- return value. represented ( )
59- } else if let value = Double ( exactly: self ) , floor ( value) != value {
60- return value. represented ( )
61- } else if let value = Int ( exactly: self ) {
62- return value. represented ( )
57+ if CFGetTypeID ( self ) == CFBooleanGetTypeID ( ) {
58+ return boolValue. represented ( )
6359 } else {
64- return Double . nan. represented ( )
60+ switch CFNumberGetType ( self ) {
61+ case . sInt8Type:
62+ return int8Value. represented ( )
63+ case . sInt16Type:
64+ return int16Value. represented ( )
65+ case . sInt32Type:
66+ return int32Value. represented ( )
67+ case . sInt64Type:
68+ return int64Value. represented ( )
69+ case . charType:
70+ return uint8Value. represented ( )
71+ case . intType, . longType, . longLongType, . nsIntegerType:
72+ return intValue. represented ( )
73+ case . float32Type, . floatType:
74+ return floatValue. represented ( )
75+ case . float64Type, . doubleType, . cgFloatType:
76+ return doubleValue. represented ( )
77+ default :
78+ return Double . nan. represented ( )
79+ }
6580 }
6681 }
6782}
0 commit comments