Skip to content

Commit

Permalink
Remove floats from the project (kernel mode compatibility) (#36)
Browse files Browse the repository at this point in the history
* Remove `float`s from the project (kernel mode compatibility)

* Bump version to v1.1.0

* Resolve PR comments

* Use integers in assertion

* Fix another comment

* Fix ZYAN_BITSET_BITS_TO_BYTES to use ints

* Don't use EXPECT_FLOAT_EQ in tests

Co-authored-by: Joel Höner <[email protected]>
  • Loading branch information
flobernd and athre0z authored Oct 26, 2021
1 parent e2b37b1 commit 636bb29
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 104 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ if (TARGET Zycore)
endif ()

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

project(Zycore VERSION 1.1.0.0 LANGUAGES C CXX)

include(GenerateExportHeader)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

project(Zycore VERSION 1.0.0.0 LANGUAGES C CXX)

# =============================================================================================== #
# Overridable options #
# =============================================================================================== #
Expand Down
2 changes: 1 addition & 1 deletion examples/Vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static ZyanStatus TestAllocator(void)
// dynamic shrinking is disabled
ZyanVector vector;
ZYAN_CHECK(ZyanVectorInitEx(&vector, sizeof(TestStruct), 5, ZYAN_NULL, &allocator,
10.0f, 0.0f));
10, 0));

static TestStruct e_v;

Expand Down
22 changes: 11 additions & 11 deletions include/Zycore/Bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ typedef ZyanStatus (*ZyanBitsetByteOperation)(ZyanU8* v1, const ZyanU8* v2);
* @return A zyan status code.
*
* The space for the bitset is dynamically allocated by the default allocator using the default
* growth factor of `2.0f` and the default shrink threshold of `0.5f`.
* growth factor and the default shrink threshold.
*/
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanBitsetInit(ZyanBitset* bitset, ZyanUSize count);

Expand All @@ -109,16 +109,16 @@ ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanBitsetInit(ZyanBitset* bitset, Z
* @param bitset A pointer to the `ZyanBitset` instance.
* @param count The initial amount of bits.
* @param allocator A pointer to a `ZyanAllocator` instance.
* @param growth_factor The growth factor (from `1.0f` to `x.xf`).
* @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`).
* @param growth_factor The growth factor.
* @param shrink_threshold The shrink threshold.
*
* @return A zyan status code.
*
* A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables
* A growth factor of `1` disables overallocation and a shrink threshold of `0` disables
* dynamic shrinking.
*/
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitEx(ZyanBitset* bitset, ZyanUSize count,
ZyanAllocator* allocator, float growth_factor, float shrink_threshold);
ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold);

/**
* Initializes the given `ZyanBitset` instance and configures it to use a custom user
Expand Down Expand Up @@ -266,7 +266,7 @@ ZYCORE_EXPORT ZyanStatus ZyanBitsetToggle(ZyanBitset* bitset, ZyanUSize index);
* @param index The bit index.
*
* @return `ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not, Another zyan
* status code, if an error occured.
* status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanBitsetTest(ZyanBitset* bitset, ZyanUSize index);

Expand All @@ -276,7 +276,7 @@ ZYCORE_EXPORT ZyanStatus ZyanBitsetTest(ZyanBitset* bitset, ZyanUSize index);
* @param bitset A pointer to the `ZyanBitset` instance.
*
* @return `ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not. Another zyan
* status code, if an error occured.
* status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestMSB(ZyanBitset* bitset);

Expand All @@ -286,7 +286,7 @@ ZYCORE_EXPORT ZyanStatus ZyanBitsetTestMSB(ZyanBitset* bitset);
* @param bitset A pointer to the `ZyanBitset` instance.
*
* @return `ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not. Another zyan
* status code, if an error occured.
* status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestLSB(ZyanBitset* bitset);

Expand Down Expand Up @@ -427,7 +427,7 @@ ZYCORE_EXPORT ZyanStatus ZyanBitsetCount(const ZyanBitset* bitset, ZyanUSize* co
* @param bitset A pointer to the `ZyanBitset` instance.
*
* @return `ZYAN_STATUS_TRUE`, if all bits are set, `ZYAN_STATUS_FALSE`, if not. Another zyan
* status code, if an error occured.
* status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanBitsetAll(const ZyanBitset* bitset);

Expand All @@ -437,7 +437,7 @@ ZYCORE_EXPORT ZyanStatus ZyanBitsetAll(const ZyanBitset* bitset);
* @param bitset A pointer to the `ZyanBitset` instance.
*
* @return `ZYAN_STATUS_TRUE`, if at least one bit is set, `ZYAN_STATUS_FALSE`, if not. Another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanBitsetAny(const ZyanBitset* bitset);

Expand All @@ -447,7 +447,7 @@ ZYCORE_EXPORT ZyanStatus ZyanBitsetAny(const ZyanBitset* bitset);
* @param bitset A pointer to the `ZyanBitset` instance.
*
* @return `ZYAN_STATUS_TRUE`, if none bits are set, `ZYAN_STATUS_FALSE`, if not. Another zyan
* status code, if an error occured.
* status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanBitsetNone(const ZyanBitset* bitset);

Expand Down
60 changes: 30 additions & 30 deletions include/Zycore/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ extern "C" {
/**
* The default growth factor for all string instances.
*/
#define ZYAN_STRING_DEFAULT_GROWTH_FACTOR 2.00f
#define ZYAN_STRING_DEFAULT_GROWTH_FACTOR 2

/**
* The default shrink threshold for all string instances.
*/
#define ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD 0.25f
#define ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD 4

/* ============================================================================================== */
/* Enums and types */
Expand All @@ -71,7 +71,7 @@ extern "C" {
/* ---------------------------------------------------------------------------------------------- */

/**
* Defines the `ZyanStringFlags` datatype.
* Defines the `ZyanStringFlags` data-type.
*/
typedef ZyanU8 ZyanStringFlags;

Expand Down Expand Up @@ -181,8 +181,8 @@ typedef struct ZyanStringView_
/* vector */ \
{ \
/* allocator */ ZYAN_NULL, \
/* growth_factor */ 1.0f, \
/* shrink_threshold */ 0.0f, \
/* growth_factor */ 1, \
/* shrink_threshold */ 0, \
/* size */ sizeof(string), \
/* capacity */ sizeof(string), \
/* element_size */ sizeof(char), \
Expand Down Expand Up @@ -213,7 +213,7 @@ typedef struct ZyanStringView_
* @return A zyan status code.
*
* The memory for the string is dynamically allocated by the default allocator using the default
* growth factor of `2.0f` and the default shrink threshold of `0.25f`.
* growth factor and the default shrink threshold.
*
* The allocated buffer will be at least one character larger than the given `capacity`, to reserve
* space for the terminating '\0'.
Expand All @@ -231,12 +231,12 @@ ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringInit(ZyanString* string, Z
* @param string A pointer to the `ZyanString` instance.
* @param capacity The initial capacity (number of characters).
* @param allocator A pointer to a `ZyanAllocator` instance.
* @param growth_factor The growth factor (from `1.0f` to `x.xf`).
* @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`).
* @param growth_factor The growth factor.
* @param shrink_threshold The shrink threshold.
*
* @return A zyan status code.
*
* A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables
* A growth factor of `1` disables overallocation and a shrink threshold of `0` disables
* dynamic shrinking.
*
* The allocated buffer will be at least one character larger than the given `capacity`, to reserve
Expand All @@ -245,7 +245,7 @@ ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringInit(ZyanString* string, Z
* Finalization with `ZyanStringDestroy` is required for all strings created by this function.
*/
ZYCORE_EXPORT ZyanStatus ZyanStringInitEx(ZyanString* string, ZyanUSize capacity,
ZyanAllocator* allocator, float growth_factor, float shrink_threshold);
ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold);

/**
* Initializes the given `ZyanString` instance and configures it to use a custom user
Expand Down Expand Up @@ -295,7 +295,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringDestroy(ZyanString* string);
* string or `destination` points to an already initialized `ZyanString` instance.
*
* The memory for the string is dynamically allocated by the default allocator using the default
* growth factor of `2.0f` and the default shrink threshold of `0.25f`.
* growth factor and the default shrink threshold.
*
* The allocated buffer will be at least one character larger than the given `capacity`, to reserve
* space for the terminating '\0'.
Expand All @@ -318,15 +318,15 @@ ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringDuplicate(ZyanString* dest
* This value is automatically adjusted to the size of the source
* string, if a smaller value was passed.
* @param allocator A pointer to a `ZyanAllocator` instance.
* @param growth_factor The growth factor (from `1.0f` to `x.xf`).
* @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`).
* @param growth_factor The growth factor.
* @param shrink_threshold The shrink threshold.
*
* @return A zyan status code.
*
* The behavior of this function is undefined, if `source` is a view into the `destination`
* string or `destination` points to an already initialized `ZyanString` instance.
*
* A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables
* A growth factor of `1` disables overallocation and a shrink threshold of `0` disables
* dynamic shrinking.
*
* The allocated buffer will be at least one character larger than the given `capacity`, to reserve
Expand All @@ -336,7 +336,7 @@ ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringDuplicate(ZyanString* dest
*/
ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateEx(ZyanString* destination,
const ZyanStringView* source, ZyanUSize capacity, ZyanAllocator* allocator,
float growth_factor, float shrink_threshold);
ZyanU8 growth_factor, ZyanU8 shrink_threshold);

/**
* Initializes a new `ZyanString` instance by duplicating an existing string and
Expand Down Expand Up @@ -387,7 +387,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateCustomBuffer(ZyanString* destination
* string or `destination` points to an already initialized `ZyanString` instance.
*
* The memory for the string is dynamically allocated by the default allocator using the default
* growth factor of `2.0f` and the default shrink threshold of `0.25f`.
* growth factor and the default shrink threshold.
*
* The allocated buffer will be at least one character larger than the given `capacity`, to reserve
* space for the terminating '\0'.
Expand All @@ -414,15 +414,15 @@ ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringConcat(ZyanString* destina
* This value is automatically adjusted to the combined size of the
* source strings, if a smaller value was passed.
* @param allocator A pointer to a `ZyanAllocator` instance.
* @param growth_factor The growth factor (from `1.0f` to `x.xf`).
* @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`).
* @param growth_factor The growth factor.
* @param shrink_threshold The shrink threshold.
*
* @return A zyan status code.
*
* The behavior of this function is undefined, if `s1` or `s2` are views into the `destination`
* string or `destination` points to an already initialized `ZyanString` instance.
*
* A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables
* A growth factor of `1` disables overallocation and a shrink threshold of `0` disables
* dynamic shrinking.
*
* The allocated buffer will be at least one character larger than the given `capacity`, to reserve
Expand All @@ -431,8 +431,8 @@ ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringConcat(ZyanString* destina
* Finalization with `ZyanStringDestroy` is required for all strings created by this function.
*/
ZYCORE_EXPORT ZyanStatus ZyanStringConcatEx(ZyanString* destination, const ZyanStringView* s1,
const ZyanStringView* s2, ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor,
float shrink_threshold);
const ZyanStringView* s2, ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor,
ZyanU8 shrink_threshold);

/**
* Initializes a new `ZyanString` instance by concatenating two existing strings and
Expand Down Expand Up @@ -531,8 +531,8 @@ ZYCORE_EXPORT ZyanStatus ZyanStringViewGetSize(const ZyanStringView* view, ZyanU
*
* @warning The string is not guaranteed to be null terminated!
*
* @param string A pointer to the `ZyanStringView` instance.
* @param value Receives a pointer to the C-style string.
* @param view A pointer to the `ZyanStringView` instance.
* @param buffer Receives a pointer to the C-style string.
*
* @return A zyan status code.
*/
Expand Down Expand Up @@ -741,7 +741,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringLPosI(const ZyanStringView* haystack,
* `index`.
*
* @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*
* The `found_index` is set to `-1`, if the needle was not found.
*/
Expand All @@ -758,7 +758,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringLPosIEx(const ZyanStringView* haystack,
* `needle`.
*
* @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*
* The `found_index` is set to `-1`, if the needle was not found.
*/
Expand All @@ -778,7 +778,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringRPos(const ZyanStringView* haystack,
* `index`.
*
* @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*
* The `found_index` is set to `-1`, if the needle was not found.
*/
Expand All @@ -795,7 +795,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringRPosEx(const ZyanStringView* haystack,
* `needle`.
*
* @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*
* The `found_index` is set to `-1`, if the needle was not found.
*/
Expand All @@ -815,7 +815,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringRPosI(const ZyanStringView* haystack,
* `index`.
*
* @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*
* The `found_index` is set to `-1`, if the needle was not found.
*/
Expand All @@ -841,7 +841,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringRPosIEx(const ZyanStringView* haystack,
* in `s1` than in `s2`.
*
* @return `ZYAN_STATUS_TRUE`, if the strings are equal, `ZYAN_STATUS_FALSE`, if not, or another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanStringCompare(const ZyanStringView* s1, const ZyanStringView* s2,
ZyanI32* result);
Expand All @@ -861,7 +861,7 @@ ZYCORE_EXPORT ZyanStatus ZyanStringCompare(const ZyanStringView* s1, const ZyanS
* in `s1` than in `s2`.
*
* @return `ZYAN_STATUS_TRUE`, if the strings are equal, `ZYAN_STATUS_FALSE`, if not, or another
* zyan status code, if an error occured.
* zyan status code, if an error occurred.
*/
ZYCORE_EXPORT ZyanStatus ZyanStringCompareI(const ZyanStringView* s1, const ZyanStringView* s2,
ZyanI32* result);
Expand Down
Loading

0 comments on commit 636bb29

Please sign in to comment.