Add an fsgn() function.
fsgn() returns -1/0/1 depending on the parameter's sign.
This commit is contained in:
parent
67e8ceefa3
commit
8e1c19df47
3 changed files with 72 additions and 0 deletions
|
@ -70,6 +70,7 @@ add_executable(${PROJECT_NAME}
|
||||||
src/worldsizenotifiable.cpp
|
src/worldsizenotifiable.cpp
|
||||||
src/worlditems.cpp
|
src/worlditems.cpp
|
||||||
src/moveable.cpp
|
src/moveable.cpp
|
||||||
|
src/fsgn.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||||
|
|
47
src/fsgn.cpp
Normal file
47
src/fsgn.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fsgn.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
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
|
24
src/fsgn.hpp
Normal file
24
src/fsgn.hpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace curry {
|
||||||
|
float fsgn (float parIn);
|
||||||
|
} //namespace curry
|
Loading…
Reference in a new issue