github.com/mattn/anko@v0.1.10/_example/scripts/toType.ank (about) 1 #!anko 2 3 # toInt with ints, floats, strings, bools 4 println("\ntoInt examples:\n===============") 5 i = 1<<63 - 1 6 println("int", i, "toInt:", toInt(i)) 7 8 i = -1 << 63 9 println("int", i, "toInt:", toInt(i)) 10 11 f = 3.141592653589793 12 println("float", f, "toInt:", toInt(f)) 13 14 f = 1.797693134862315708145274237317043567981e18 15 println("float", f, "toInt:", toInt(f)) 16 17 f = -1.797693134862315708145274237317043567981e18 18 println("float", f, "toInt:", toInt(f)) 19 20 s = "4611686018427387904" 21 println("string", s, "toInt:", toInt(s)) 22 23 s = "-9223372036854775808" 24 println("string", s, "toInt:", toInt(s)) 25 26 s = "3.141592653589793" 27 println("string", s, "toInt:", toInt(s)) 28 29 s = "1.797693134862315708145274237317043567981e18" 30 println("string", s, "toInt:", toInt(s)) 31 32 s = "-1.797693134862315708145274237317043567981e18" 33 println("string", s, "toInt:", toInt(s)) 34 35 s = "1.797693134862315708145274237317043567981e-18" 36 println("string", s, "toInt:", toInt(s)) 37 38 b = true 39 println("bool", b, "toInt:", toInt(b)) 40 41 b = false 42 println("bool", b, "toInt:", toInt(b)) 43 44 println("\ntoFloat examples:\n=================") 45 i = 1<<63 - 1 46 println("int", i, "toFloat:", toFloat(i)) 47 48 i = -1 << 63 49 println("int", i, "toFloat:", toFloat(i)) 50 51 s = "4611686018427387904" 52 println("string", s, "toFloat:", toFloat(s)) 53 54 s = "-9223372036854775808" 55 println("string", s, "toFloat:", toFloat(s)) 56 57 s = "3.141592653589793" 58 println("string", s, "toFloat:", toFloat(s)) 59 60 s = "1.797693134862315708145274237317043567981e18" 61 println("string", s, "toFloat:", toFloat(s)) 62 63 s = "-1.797693134862315708145274237317043567981e18" 64 println("string", s, "toFloat:", toFloat(s)) 65 66 s = "1.797693134862315708145274237317043567981e-18" 67 println("string", s, "toFloat:", toFloat(s)) 68 69 b = true 70 println("bool", b, "toFloat:", toFloat(b)) 71 72 b = false 73 println("bool", b, "toFloat:", toFloat(b)) 74 75 println("\ntoBool examples:\n================") 76 i = 1 77 println("int", i, "toBool:", toBool(i)) 78 79 i = 0 80 println("int", i, "toBool:", toBool(i)) 81 82 i = -1 83 println("int", i, "toBool:", toBool(i)) 84 85 f = 1.0 86 println("float", f, "toBool:", toBool(f)) 87 88 f = 0.000000000001 89 println("float", f, "toBool:", toBool(f)) 90 91 f = 0.0 92 println("float", f, "toBool:", toBool(f)) 93 94 f = -0.0 95 println("float", f, "toBool:", toBool(f)) 96 97 s = "y" 98 println("string", s, "toBool:", toBool(s)) 99 100 s = "yEs" 101 println("string", s, "toBool:", toBool(s)) 102 103 s = "t" 104 println("string", s, "toBool:", toBool(s)) 105 106 s = "TrUe" 107 println("string", s, "toBool:", toBool(s)) 108 109 s = "1" 110 println("string", s, "toBool:", toBool(s)) 111 112 s = "0" 113 println("string", s, "toBool:", toBool(s)) 114 115 s = "f" 116 println("string", s, "toBool:", toBool(s)) 117 118 s = "FaLsE" 119 println("string", s, "toBool:", toBool(s)) 120 121 s = "foobar" 122 println("string", s, "toBool:", toBool(s)) 123