diff --git a/CMakeLists.txt b/CMakeLists.txt index ddae753..b6cd827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ add_executable(${PROJECT_NAME} src/worldsizenotifiable.cpp src/worlditems.cpp src/moveable.cpp + src/fsgn.cpp ) target_include_directories(${PROJECT_NAME} SYSTEM diff --git a/src/fsgn.cpp b/src/fsgn.cpp new file mode 100644 index 0000000..fb16340 --- /dev/null +++ b/src/fsgn.cpp @@ -0,0 +1,47 @@ +/* + Copyright 2016, 2017 Michele "King_DuckZ" Santullo + + This file is part of MyCurry. + + MyCurry is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + MyCurry is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with MyCurry. If not, see . +*/ + +#include "fsgn.hpp" +#include + +namespace curry { + //float fsgn (float parIn) { + // if (parIn < 0.0f) return -1.0f; + // if (parIn > 0.0f) return 1.0f; + // return 0.0f; + //} + + float fsgn (float parIn) { + static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected float size"); + union { + uint32_t i; + float f; + } in, r; + + in.f = parIn; + if ((in.i & 0x7FFFFFFF) == 0) { + return 0.0f; + } + else { + r.f = 1.0f; + r.i |= in.i & 0x80000000; + return r.f; + } + } +} //namespace curry diff --git a/src/fsgn.hpp b/src/fsgn.hpp new file mode 100644 index 0000000..28f3f76 --- /dev/null +++ b/src/fsgn.hpp @@ -0,0 +1,24 @@ +/* + Copyright 2016, 2017 Michele "King_DuckZ" Santullo + + This file is part of MyCurry. + + MyCurry is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + MyCurry is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with MyCurry. If not, see . +*/ + +#pragma once + +namespace curry { + float fsgn (float parIn); +} //namespace curry