switched to GPLv3 ONLY, because i don't trust FSF anymore
[gaemu.git] / gaem / runner / value.d
blobe27c100763ab52b7edb9d463dd37e450b522f0ea
1 /* GML runner
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module gaem.runner.value is aliced;
19 import gaem.runner.strpool;
22 // ////////////////////////////////////////////////////////////////////////// //
23 alias Real = double;
26 // value manipulation
27 bool isReal (Real v) nothrow @safe @nogc {
28 pragma(inline, true);
29 import std.math;
30 return !isNaN(v);
34 bool isString (Real v) nothrow @safe @nogc {
35 pragma(inline, true);
36 import std.math;
37 return isNaN(v);
41 bool isUndef (Real v) nothrow @safe @nogc {
42 pragma(inline, true);
43 import std.math;
44 return (isNaN(v) && getNaNPayload(v) < 0);
48 // creates "undefined" value
49 Real undefValue () nothrow @safe @nogc {
50 pragma(inline, true);
51 import std.math;
52 return NaN(-666);
56 // for invalid strings it returns 0
57 int getStrId (Real v) nothrow @safe @nogc {
58 pragma(inline, true);
59 import std.math;
60 if (isNaN(v)) {
61 auto res = getNaNPayload(v);
62 static if (Real.sizeof == 4) {
63 return (res < 0 ? 0 : cast(int)res);
64 } else {
65 return (res < 0 || res > int.max ? 0 : cast(int)res);
67 } else {
68 return 0;
73 Real buildStrId (int id) nothrow @safe @nogc {
74 pragma(inline, true);
75 import std.math;
76 static if (Real.sizeof == 4) {
77 assert(id >= 0 && id <= 0x3F_FFFF);
78 } else {
79 assert(id >= 0);
81 return NaN(id);
85 Real Value () nothrow @safe @nogc { pragma(inline, true); return undefValue(); }
87 Real Value(T) (T v) {
88 pragma(inline, true);
89 static if (is(T : const(char)[])) return buildStrId(newDynStr(v));
90 else static if (is(T : Real)) return cast(Real)v;
91 else static assert(0, "invalid value type");