Provide the types f_number_signed and f_number_unsigned as a way to define the default "number" type to be used for string to number conversions and array indexes.
By providing 32-bit, 64-bit (default), and 128-bit types, the type can then be adjusted to more easily work on limited hardware or expand to more capable hardware.
This will be the recommended number data type to use in FLL functions going forward.
* - other: parameters using neither minus nor plus sign, such as 'build'.
*/
#ifndef _di_f_console_types_
- typedef unsigned short f_console_id;
+ typedef uint16_t f_console_id;
enum {
f_console_result_none = 1,
#ifndef _di_f_console_parameters_
typedef struct {
f_console_parameter *parameter;
- f_array_length used;
+
+ f_array_length used;
} f_console_parameters;
#define f_console_parameters_initialize { 0, 0 }
typedef struct {
f_console_parameter_id *id;
- f_array_length used;
+
+ f_array_length used;
} f_console_parameter_ids;
#define f_console_parameter_ids_initialize { 0, 0 }
*/
#ifndef _di_f_console_arguments_
typedef struct {
- const unsigned long argc;
+ const f_number_unsigned argc;
const f_string *argv;
} f_console_arguments;
#endif // _di_f_conversion_character_is_octal_
#ifndef _di_f_conversion_character_to_binary_
- f_return_status f_conversion_character_to_binary(const int8_t character, uint64_t *number) {
+ f_return_status f_conversion_character_to_binary(const int8_t character, f_number_unsigned *number) {
#ifndef _di_level_0_parameter_checking_
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
#endif // _di_f_conversion_character_to_binary_
#ifndef _di_f_conversion_character_to_decimal_
- f_return_status f_conversion_character_to_decimal(const int8_t character, uint64_t *number) {
+ f_return_status f_conversion_character_to_decimal(const int8_t character, f_number_unsigned *number) {
#ifndef _di_level_0_parameter_checking_
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
#endif // _di_f_conversion_character_to_decimal_
#ifndef _di_f_conversion_character_to_duodecimal_
- f_return_status f_conversion_character_to_duodecimal(const int8_t character, uint64_t *decimal) {
+ f_return_status f_conversion_character_to_duodecimal(const int8_t character, f_number_unsigned *decimal) {
#ifndef _di_level_0_parameter_checking_
if (decimal == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
#endif // _di_f_conversion_character_to_duodecimal_
#ifndef _di_f_conversion_character_to_hexidecimal_
- f_return_status f_conversion_character_to_hexidecimal(const int8_t character, uint64_t *decimal) {
+ f_return_status f_conversion_character_to_hexidecimal(const int8_t character, f_number_unsigned *decimal) {
#ifndef _di_level_0_parameter_checking_
if (decimal == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
#endif // _di_f_conversion_character_to_hexidecimal_
#ifndef _di_f_conversion_character_to_octal_
- f_return_status f_conversion_character_to_octal(const int8_t character, uint64_t *number) {
+ f_return_status f_conversion_character_to_octal(const int8_t character, f_number_unsigned *number) {
#ifndef _di_level_0_parameter_checking_
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
#endif // _di_f_conversion_character_to_octal_
#ifndef _di_f_conversion_string_to_binary_signed_
- f_return_status f_conversion_string_to_binary_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative) {
+ f_return_status f_conversion_string_to_binary_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_binary(string[i], &digit) == f_none) {
if (scale) {
scale++;
- if (scale > 63) {
- return f_status_set_error(f_overflow);
- }
-
if (negative) {
- if (scale > 63) {
+ if (scale > f_conversion_scale_binary_signed) {
return f_status_set_error(f_underflow);
}
converted -= digit;
}
else {
- if (scale > 63) {
+ if (scale > f_conversion_scale_binary_signed) {
return f_status_set_error(f_overflow);
}
#endif // _di_f_conversion_string_to_binary_signed_
#ifndef _di_f_conversion_string_to_binary_unsigned_
- f_return_status f_conversion_string_to_binary_unsigned(const f_string string, uint64_t *number, const f_string_location location) {
+ f_return_status f_conversion_string_to_binary_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_binary(string[i], &digit) == f_none) {
if (scale) {
scale++;
- if (scale > 64) {
+ if (scale > f_conversion_scale_binary_unsigned) {
return f_status_set_error(f_overflow);
}
#endif // _di_f_conversion_string_to_binary_unsigned_
#ifndef _di_f_conversion_string_to_decimal_signed_
- f_return_status f_conversion_string_to_decimal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative) {
+ f_return_status f_conversion_string_to_decimal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_decimal(string[i], &digit) == f_none) {
scale++;
if (negative) {
- if (scale > 18) {
- if ((converted * 10) - digit < LLONG_MIN || (converted * 10) - digit > converted) {
+ if (scale > f_conversion_scale_decimal_signed) {
+ if ((converted * 10) - digit < f_type_number_size_negative || (converted * 10) - digit > converted) {
return f_status_set_error(f_underflow);
}
}
converted -= digit;
}
else {
- if (scale > 18) {
- if ((converted * 10) + digit > LLONG_MAX || (converted * 10) + digit < converted) {
+ if (scale > f_conversion_scale_decimal_signed) {
+ if ((converted * 10) + digit > f_type_number_size_positive || (converted * 10) + digit < converted) {
return f_status_set_error(f_overflow);
}
}
#endif // _di_f_conversion_string_to_decimal_signed_
#ifndef _di_f_conversion_string_to_decimal_unsigned_
- f_return_status f_conversion_string_to_decimal_unsigned(const f_string string, uint64_t *number, const f_string_location location) {
+ f_return_status f_conversion_string_to_decimal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_decimal(string[i], &digit) == f_none) {
if (scale) {
scale++;
- if (scale > 18) {
- if ((converted * 10) + digit > ULLONG_MAX || (converted * 10) + digit < converted) {
+ if (scale > f_conversion_scale_decimal_unsigned) {
+ if ((converted * 10) + digit > f_type_number_size_unsigned || (converted * 10) + digit < converted) {
return f_status_set_error(f_overflow);
}
}
#endif // _di_f_conversion_string_to_decimal_unsigned_
#ifndef _di_f_conversion_string_to_duodecimal_signed_
- f_return_status f_conversion_string_to_duodecimal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative) {
+ f_return_status f_conversion_string_to_duodecimal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_duodecimal(string[i], &digit) == f_none) {
scale++;
if (negative) {
- if (scale > 15) {
- if ((converted * 12) - digit < LLONG_MIN || (converted * 12) - digit > converted) {
+ if (scale > f_conversion_scale_duodecimal_signed) {
+ if ((converted * 12) - digit < f_type_number_size_negative || (converted * 12) - digit > converted) {
return f_status_set_error(f_underflow);
}
}
converted -= digit;
}
else {
- if (scale > 15) {
- if ((converted * 12) + digit > LLONG_MAX || (converted * 12) + digit < converted) {
+ if (scale > f_conversion_scale_duodecimal_signed) {
+ if ((converted * 12) + digit > f_type_number_size_positive || (converted * 12) + digit < converted) {
return f_status_set_error(f_overflow);
}
}
#endif // _di_f_conversion_string_to_duodecimal_signed_
#ifndef _di_f_conversion_string_to_duodecimal_unsigned_
- f_return_status f_conversion_string_to_duodecimal_unsigned(const f_string string, uint64_t *number, const f_string_location location) {
+ f_return_status f_conversion_string_to_duodecimal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_duodecimal(string[i], &digit) == f_none) {
if (scale) {
scale++;
- if (scale > 16) {
- if ((converted * 12) + digit > ULLONG_MAX || (converted * 12) + digit < converted) {
+ if (scale > f_conversion_scale_duodecimal_unsigned) {
+ if ((converted * 12) + digit > f_type_number_size_unsigned || (converted * 12) + digit < converted) {
return f_status_set_error(f_overflow);
}
}
#endif // _di_f_conversion_string_to_duodecimal_unsigned_
#ifndef _di_f_conversion_string_to_hexidecimal_signed_
- f_return_status f_conversion_string_to_hexidecimal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative) {
+ f_return_status f_conversion_string_to_hexidecimal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_hexidecimal(string[i], &digit) == f_none) {
scale++;
if (negative) {
- if (scale > 15) {
- if ((converted << 4) - digit < LLONG_MIN || (converted << 4) - digit > converted) {
+ if (scale > f_conversion_scale_hexidecimal_signed) {
+ if ((converted << 4) - digit < f_type_number_size_negative || (converted << 4) - digit > converted) {
return f_status_set_error(f_underflow);
}
}
converted -= digit;
}
else {
- if (scale > 15) {
- if ((converted << 4) + digit > LLONG_MAX || (converted << 4) + digit < converted) {
+ if (scale > f_conversion_scale_hexidecimal_signed) {
+ if ((converted << 4) + digit > f_type_number_size_positive || (converted << 4) + digit < converted) {
return f_status_set_error(f_overflow);
}
}
#endif // _di_f_conversion_string_to_hexidecimal_signed_
#ifndef _di_f_conversion_string_to_hexidecimal_unsigned_
- f_return_status f_conversion_string_to_hexidecimal_unsigned(const f_string string, uint64_t *number, const f_string_location location) {
+ f_return_status f_conversion_string_to_hexidecimal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_hexidecimal(string[i], &digit) == f_none) {
if (scale) {
scale++;
- if (scale > 16) {
- return f_status_set_error(f_overflow);
+ if (scale > f_conversion_scale_hexidecimal_unsigned) {
+ if ((converted << 4) + digit > f_type_number_size_unsigned || (converted << 4) + digit < converted) {
+ return f_status_set_error(f_overflow);
+ }
}
converted <<= 4;
#endif // _di_f_conversion_string_to_hexidecimal_unsigned_
#ifndef _di_f_conversion_string_to_octal_signed_
- f_return_status f_conversion_string_to_octal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative) {
+ f_return_status f_conversion_string_to_octal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_octal(string[i], &digit) == f_none) {
scale++;
if (negative) {
- if (scale > 19) {
- if ((converted << 3) - digit < LLONG_MIN || (converted << 3) - digit > converted) {
+ if (scale > f_conversion_scale_octal_signed) {
+ if ((converted << 3) - digit < f_type_number_size_negative || (converted << 3) - digit > converted) {
return f_status_set_error(f_underflow);
}
}
converted -= digit;
}
else {
- if (scale > 19) {
- if ((converted << 3) + digit > LLONG_MAX || (converted << 3) + digit < converted) {
+ if (scale > f_conversion_scale_octal_signed) {
+ if ((converted << 3) + digit > f_type_number_size_positive || (converted << 3) + digit < converted) {
return f_status_set_error(f_overflow);
}
}
#endif // _di_f_conversion_string_to_octal_signed_
#ifndef _di_f_conversion_string_to_octal_unsigned_
- f_return_status f_conversion_string_to_octal_unsigned(const f_string string, uint64_t *number, const f_string_location location) {
+ f_return_status f_conversion_string_to_octal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
uint8_t scale = 0;
- uint64_t digit = 0;
- uint64_t converted = 0;
+ f_number_unsigned digit = 0;
+ f_number_unsigned converted = 0;
for (f_string_length i = location.start; i <= location.stop; i++) {
if (f_conversion_character_to_octal(string[i], &digit) == f_none) {
if (scale) {
scale++;
- if (scale > 20) {
- if ((converted << 3) + digit > ULLONG_MAX || (converted << 3) + digit < converted) {
+ if (scale > f_conversion_scale_octal_unsigned) {
+ if ((converted << 3) + digit > f_type_number_size_unsigned || (converted << 3) + digit < converted) {
return f_status_set_error(f_overflow);
}
}
#endif // _di_f_conversion_string_to_octal_unsigned_
#ifndef _di_f_conversion_string_to_number_signed_
- f_return_status f_conversion_string_to_number_signed(const f_string string, int64_t *number, const f_string_location location) {
+ f_return_status f_conversion_string_to_number_signed(const f_string string, f_number_signed *number, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
break;
}
- return f_status_set_error(f_negative_number);
+ return f_status_set_error(f_invalid_number);
} // for
if (mode == 0) {
#endif // _di_f_conversion_string_to_number_signed_
#ifndef _di_f_conversion_string_to_number_unsigned_
- f_return_status f_conversion_string_to_number_unsigned(const f_string string, uint64_t *number, const f_string_location location) {
+ f_return_status f_conversion_string_to_number_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (string == 0) return f_status_set_error(f_invalid_parameter);
if (number == 0) return f_status_set_error(f_invalid_parameter);
break;
}
- return f_status_set_error(f_negative_number);
+ return f_status_set_error(f_invalid_number);
} // for
if (mode == 0) {
// libc includes
#include <ctype.h>
-#include <limits.h>
#include <stdlib.h>
// fll-0 includes
#endif
/**
+ * Provide custom conversion scale limits based on selected type sizes.
+ *
+ * Utilize the f_type_number_* defines to determine the expected sizes to use for the sxcales.
+ *
+ * 64-bit is the designed default.
+ */
+#ifndef _di_f_type_number_64_
+ #define f_conversion_scale_binary_unsigned 64
+ #define f_conversion_scale_binary_signed 63
+
+ #define f_conversion_scale_octal_unsigned 21
+ #define f_conversion_scale_octal_signed 20
+
+ #define f_conversion_scale_decimal_unsigned 19
+ #define f_conversion_scale_decimal_signed 18
+
+ #define f_conversion_scale_duodecimal_unsigned 17
+ #define f_conversion_scale_duodecimal_signed 17
+
+ #define f_conversion_scale_hexidecimal_unsigned 15
+ #define f_conversion_scale_hexidecimal_signed 15
+#endif // _di_f_type_number_64_
+
+#ifdef _en_f_type_number_32_
+ #define f_conversion_scale_binary_unsigned 32
+ #define f_conversion_scale_binary_signed 31
+
+ #define f_conversion_scale_octal_unsigned 10
+ #define f_conversion_scale_octal_signed 10
+
+ #define f_conversion_scale_decimal_unsigned 9
+ #define f_conversion_scale_decimal_signed 9
+
+ #define f_conversion_scale_duodecimal_unsigned 8
+ #define f_conversion_scale_duodecimal_signed 8
+
+ #define f_conversion_scale_hexidecimal_unsigned 7
+ #define f_conversion_scale_hexidecimal_signed 7
+#endif // _en_f_type_number_32_
+
+#ifdef _en_f_type_number_128_
+ #define f_conversion_scale_binary_unsigned 128
+ #define f_conversion_scale_binary_signed 127
+
+ #define f_conversion_scale_octal_unsigned 42
+ #define f_conversion_scale_octal_signed 42
+
+ #define f_conversion_scale_decimal_unsigned 38
+ #define f_conversion_scale_decimal_signed 38
+
+ #define f_conversion_scale_duodecimal_unsigned 35
+ #define f_conversion_scale_duodecimal_signed 35
+
+ #define f_conversion_scale_hexidecimal_unsigned 31
+ #define f_conversion_scale_hexidecimal_signed 31
+#endif // _en_f_type_number_128_
+
+/**
* Convert a single character into the binary digit that it represents.
*
* @param character
* f_invalid_parameter (with error bit) if a parameter is invalid.
*/
#ifndef _di_f_conversion_character_to_binary_
- extern f_return_status f_conversion_character_to_binary(const int8_t character, uint64_t *number);
+ extern f_return_status f_conversion_character_to_binary(const int8_t character, f_number_unsigned *number);
#endif // _di_f_conversion_character_to_binary_
/**
* f_invalid_parameter (with error bit) if a parameter is invalid.
*/
#ifndef _di_f_conversion_character_to_decimal_
- extern f_return_status f_conversion_character_to_decimal(const int8_t character, uint64_t *number);
+ extern f_return_status f_conversion_character_to_decimal(const int8_t character, f_number_unsigned *number);
#endif // _di_f_conversion_character_to_decimal_
/**
* f_invalid_parameter (with error bit) if a parameter is invalid.
*/
#ifndef _di_f_conversion_character_to_duodecimal_
- extern f_return_status f_conversion_character_to_duodecimal(const int8_t character, uint64_t *number);
+ extern f_return_status f_conversion_character_to_duodecimal(const int8_t character, f_number_unsigned *number);
#endif // _di_f_conversion_character_to_duodecimal_
/**
* f_invalid_parameter (with error bit) if a parameter is invalid.
*/
#ifndef _di_f_conversion_character_to_hexidecimal_
- extern f_return_status f_conversion_character_to_hexidecimal(const int8_t character, uint64_t *number);
+ extern f_return_status f_conversion_character_to_hexidecimal(const int8_t character, f_number_unsigned *number);
#endif // _di_f_conversion_character_to_hexidecimal_
/**
* f_invalid_parameter (with error bit) if a parameter is invalid.
*/
#ifndef _di_f_conversion_character_to_octal_
- extern f_return_status f_conversion_character_to_octal(const int8_t character, uint64_t *number);
+ extern f_return_status f_conversion_character_to_octal(const int8_t character, f_number_unsigned *number);
#endif // _di_f_conversion_character_to_octal_
/**
- * Convert a series of positive or negative binary number characters into a int64_t.
+ * Convert a series of positive or negative binary number characters into a f_number_signed.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_underflow (with error bit) on integer underflow.
*/
#ifndef _di_f_conversion_string_to_binary_signed_
- extern f_return_status f_conversion_string_to_binary_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative);
+ extern f_return_status f_conversion_string_to_binary_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative);
#endif // _di_f_conversion_string_to_binary_signed_
/**
- * Convert a series of positive binary number characters into a uint64_t.
+ * Convert a series of positive binary number characters into a f_number_unsigned.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_overflow (with error bit) on integer overflow.
*/
#ifndef _di_f_conversion_string_to_binary_unsigned_
- extern f_return_status f_conversion_string_to_binary_unsigned(const f_string string, uint64_t *number, const f_string_location location);
+ extern f_return_status f_conversion_string_to_binary_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location);
#endif // _di_f_conversion_string_to_binary_unsigned_
/**
- * Convert a series of positive or negative decimal number characters into an int64_t.
+ * Convert a series of positive or negative decimal number characters into an f_number_signed.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_underflow (with error bit) on integer underflow.
*/
#ifndef _di_f_conversion_string_to_decimal_signed_
- extern f_return_status f_conversion_string_to_decimal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative);
+ extern f_return_status f_conversion_string_to_decimal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative);
#endif // _di_f_conversion_string_to_decimal_signed_
/**
- * Convert a series of positive decimal number characters into an uint64_t.
+ * Convert a series of positive decimal number characters into an f_number_unsigned.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_overflow (with error bit) on integer overflow.
*/
#ifndef _di_f_conversion_string_to_decimal_unsigned_
- extern f_return_status f_conversion_string_to_decimal_unsigned(const f_string string, uint64_t *number, const f_string_location location);
+ extern f_return_status f_conversion_string_to_decimal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location);
#endif // _di_f_conversion_string_to_decimal_unsigned_
/**
- * Convert a series of positive or negative duodecimal number characters into an int64_t.
+ * Convert a series of positive or negative duodecimal number characters into an f_number_signed.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_underflow (with error bit) on integer underflow.
*/
#ifndef _di_f_conversion_string_to_duodecimal_signed_
- extern f_return_status f_conversion_string_to_duodecimal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative);
+ extern f_return_status f_conversion_string_to_duodecimal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative);
#endif // _di_f_conversion_string_to_duodecimal_signed_
/**
- * Convert a series of positive duodecimal number characters into an uint64_t.
+ * Convert a series of positive duodecimal number characters into an f_number_unsigned.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_overflow (with error bit) on integer overflow.
*/
#ifndef _di_f_conversion_string_to_duodecimal_unsigned_
- extern f_return_status f_conversion_string_to_duodecimal_unsigned(const f_string string, uint64_t *number, const f_string_location location);
+ extern f_return_status f_conversion_string_to_duodecimal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location);
#endif // _di_f_conversion_string_to_duodecimal_unsigned_
/**
- * Convert a series of positive or negative hexidecimal number characters into an int64_t.
+ * Convert a series of positive or negative hexidecimal number characters into an f_number_signed.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_underflow (with error bit) on integer underflow.
*/
#ifndef _di_f_conversion_string_to_hexidecimal_signed_
- extern f_return_status f_conversion_string_to_hexidecimal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative);
+ extern f_return_status f_conversion_string_to_hexidecimal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative);
#endif // _di_f_conversion_string_to_hexidecimal_signed_
/**
- * Convert a series of positive hexidecimal number characters into an uint64_t.
+ * Convert a series of positive hexidecimal number characters into an f_number_unsigned.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_overflow (with error bit) on integer overflow.
*/
#ifndef _di_f_conversion_string_to_hexidecimal_unsigned_
- extern f_return_status f_conversion_string_to_hexidecimal_unsigned(const f_string string, uint64_t *number, const f_string_location location);
+ extern f_return_status f_conversion_string_to_hexidecimal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location);
#endif // _di_f_conversion_string_to_hexidecimal_unsigned_
/**
- * Convert a series of positive or negative octal number characters into an int64_t.
+ * Convert a series of positive or negative octal number characters into an f_number_signed.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_overflow (with error bit) on integer overflow.
*/
#ifndef _di_f_conversion_string_to_octal_signed_
- extern f_return_status f_conversion_string_to_octal_signed(const f_string string, int64_t *number, const f_string_location location, const bool negative);
+ extern f_return_status f_conversion_string_to_octal_signed(const f_string string, f_number_signed *number, const f_string_location location, const bool negative);
#endif // _di_f_conversion_string_to_octal_signed_
/**
- * Convert a series of positive octal number characters into an uint64_t.
+ * Convert a series of positive octal number characters into an f_number_unsigned.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* f_overflow (with error bit) on integer overflow.
*/
#ifndef _di_f_conversion_string_to_octal_unsigned_
- extern f_return_status f_conversion_string_to_octal_unsigned(const f_string string, uint64_t *number, const f_string_location location);
+ extern f_return_status f_conversion_string_to_octal_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location);
#endif // _di_f_conversion_string_to_octal_unsigned_
/**
- * Convert a series of positive or negative number characters into an int64_t.
+ * Convert a series of positive or negative number characters into an f_number_signed.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* @see strtoll()
*/
#ifndef _di_f_conversion_string_to_number_signed_
- extern f_return_status f_conversion_string_to_number_signed(const f_string string, int64_t *number, const f_string_location location);
+ extern f_return_status f_conversion_string_to_number_signed(const f_string string, f_number_signed *number, const f_string_location location);
#endif // _di_f_conversion_string_to_number_signed_
/**
- * Convert a series of positive number characters into an uint64_t.
+ * Convert a series of positive number characters into an f_number_unsigned.
*
* This will stop at one of the following: location.stop or a non-digit.
* This will ignore NULL values.
* @see strtoull()
*/
#ifndef _di_f_conversion_string_to_number_unsigned_
- extern f_return_status f_conversion_string_to_number_unsigned(const f_string string, uint64_t *number, const f_string_location location);
+ extern f_return_status f_conversion_string_to_number_unsigned(const f_string string, f_number_unsigned *number, const f_string_location location);
#endif // _di_f_conversion_string_to_number_unsigned_
#ifdef __cplusplus
#ifndef _di_f_string_
typedef char *f_string;
- #define f_string_max_size f_type_size_32_signed
+ #define f_string_max_size f_type_number_size_unsigned
#define f_string_initialize f_string_eos
#define f_macro_string_new(status, string, length) status = f_memory_new((void **) & string, sizeof(f_string), length)
#endif // _di_f_string_
#ifndef _di_f_string_length_
- typedef uint64_t f_string_length;
+ typedef f_number_unsigned f_string_length;
#define f_string_length_printf string_format_long_integer
#ifndef _di_f_string_lengths_
typedef struct {
f_string_length *array;
- f_array_length size;
- f_array_length used;
+
+ f_array_length size;
+ f_array_length used;
} f_string_lengths;
#define f_string_lengths_initialize { 0, 0, 0 }
#ifndef _di_f_string_locations_
typedef struct {
f_string_location *array;
- f_array_length size;
- f_array_length used;
+
+ f_array_length size;
+ f_array_length used;
} f_string_locations;
#define f_string_locations_initialize {0, 0, 0}
*/
#ifndef _di_f_string_dynamic_
typedef struct {
- f_string string;
+ f_string string;
+
f_string_length size;
f_string_length used;
} f_string_dynamic;
#ifndef _di_f_string_dynamics_
typedef struct {
f_string_dynamic *array;
- f_string_length size;
- f_string_length used;
+
+ f_string_length size;
+ f_string_length used;
} f_string_dynamics;
#define f_string_dynamics_initialize { 0, 0, 0 }
*
* The size is to be the (max supported size - 1) such that that last number can be used for overflow operations.
*
+ * For example, f_type_size_8_negative is 2^7, or -1 to -128, therefore the max size here is -128 - 1 or -127.
+ * For example, f_type_size_8_positive is 2^7, or 0 to 127, therefore the max size here is 127 - 1 or 126.
* For example, f_type_size_8_unsigned is 2^8, or 0 to 255, therefore the max size here is 255 - 1 or 254.
- * For example, f_type_size_8_signed is 2^7, or 0 to 127, therefore the max size here is 127 - 1 or 126.
*
* The max_size is provided for actual max sizes.
+ * For example, f_type_size_8_negative is 2^7, or -1 to -128, therefore the max size here is -128.
+ * For example, f_type_size_8_positive is 2^7, or 0 to 127, therefore the max size here is 127.
* For example, f_type_size_8_unsigned is 2^8, or 0 to 255, therefore the max size here is 255.
- * For example, f_type_size_8_signed is 2^7, or 0 to 127, therefore the max size here is 127.
*/
#ifndef _di_f_type_sizes_
- #define f_type_size_8_unsigned 0xfe
- #define f_type_size_8_signed 0x7e
- #define f_type_size_16_unsigned 0xfffe
- #define f_type_size_16_signed 0x7ffe
- #define f_type_size_32_unsigned 0xfffffffe
- #define f_type_size_32_signed 0x7ffffffe
- #define f_type_size_64_unsigned 0xfffffffffffffffe
- #define f_type_size_64_signed 0x7ffffffffffffffe
- //#define f_type_size_128_unsigned 0xfffffffffffffffffffffffe
- //#define f_type_size_128_signed 0x7ffffffffffffffffffffffe
-
- #define f_type_size_max_8_unsigned 0xff
- #define f_type_size_max_8_signed 0x7f
- #define f_type_size_max_16_unsigned 0xffff
- #define f_type_size_max_16_signed 0x7fff
- #define f_type_size_max_32_unsigned 0xffffffff
- #define f_type_size_max_32_signed 0x7fffffff
- #define f_type_size_max_64_unsigned 0xffffffffffffffff
- #define f_type_size_max_64_signed 0x7fffffffffffffff
- //#define f_type_size_max_128_unsigned 0xffffffffffffffffffffffff
- //#define f_type_size_max_128_signed 0x7fffffffffffffffffffffff
+ #define f_type_size_8_negative 0x7f
+ #define f_type_size_8_positive 0x7e
+ #define f_type_size_8_unsigned 0xfe
+
+ #define f_type_size_16_negative 0x7fff
+ #define f_type_size_16_positive 0x7ffe
+ #define f_type_size_16_unsigned 0xfffe
+
+ #define f_type_size_32_negative 0x7fffffff
+ #define f_type_size_32_positive 0x7ffffffe
+ #define f_type_size_32_unsigned 0xfffffffe
+
+ #define f_type_size_64_negative 0x7fffffffffffffff
+ #define f_type_size_64_positive 0x7ffffffffffffffe
+ #define f_type_size_64_unsigned 0xfffffffffffffffe
+
+ #ifndef _di_f_type_int_128_
+ #define f_type_size_128_negative 0x7fffffffffffffffffffffff
+ #define f_type_size_128_positive 0x7ffffffffffffffffffffffe
+ #define f_type_size_128_unsigned 0xfffffffffffffffffffffffe
+ #else
+ #define f_type_size_128_negative f_type_size_64_negative
+ #define f_type_size_128_positive f_type_size_64_positive
+ #define f_type_size_128_unsigned f_type_size_64_unsigned
+ #endif // _di_f_type_int_128_
+
+ #define f_type_size_max_8_negative 0x80
+ #define f_type_size_max_8_positive 0x7f
+ #define f_type_size_max_8_unsigned 0xff
+
+ #define f_type_size_max_16_negative 0x8000
+ #define f_type_size_max_16_positive 0x7fff
+ #define f_type_size_max_16_unsigned 0xffff
+
+ #define f_type_size_max_32_negative 0x80000000
+ #define f_type_size_max_32_positive 0x7fffffff
+ #define f_type_size_max_32_unsigned 0xffffffff
+
+ #define f_type_size_max_64_negative 0x8000000000000000
+ #define f_type_size_max_64_positive 0x7fffffffffffffff
+ #define f_type_size_max_64_unsigned 0xffffffffffffffff
+
+ #ifndef _di_f_type_int_128_
+ #define f_type_size_max_128_negative 0x800000000000000000000000
+ #define f_type_size_max_128_positive 0x7fffffffffffffffffffffff
+ #define f_type_size_max_128_unsigned 0xffffffffffffffffffffffff
+ #else
+ #define f_type_size_max_128_negative f_type_size_max_64_negative
+ #define f_type_size_max_128_positive f_type_size_max_64_positive
+ #define f_type_size_max_128_unsigned f_type_size_max_64_unsigned
+ #endif // _di_f_type_int_128_
#endif // _di_f_type_sizes_
/**
+ * Custom data type to be used throughout the project to represent general numbers.
+ *
+ * This is intended to be used in buffers, such as strings, and in argument parameters.
+ *
+ * Provides additional custom types so that it can be more easily be overwritten.
+ * Specifically, there is support for using 32-bit, 64-bit or 128-bit lengths.
+ *
+ * 64-bit is the designed default.
+ */
+#ifndef _di_f_type_number_64_
+ typedef int64_t f_number_signed;
+ typedef uint64_t f_number_unsigned;
+
+ #define f_type_number_size_unsigned f_type_size_64_unsigned
+ #define f_type_number_size_positive f_type_size_64_positive
+ #define f_type_number_size_negative f_type_size_64_negative
+
+ #define f_type_number_size_max_unsigned f_type_size_max_64_unsigned
+ #define f_type_number_size_max_positive f_type_size_max_64_positive
+ #define f_type_number_size_max_negative f_type_size_max_64_negative
+#endif // _di_f_type_number_64_
+
+#ifdef _en_f_type_number_32_
+ typedef int32_t f_number_signed;
+ typedef uint32_t f_number_unsigned;
+
+ #define f_type_number_size_unsigned f_type_size_32_unsigned
+ #define f_type_number_size_positive f_type_size_32_positive
+ #define f_type_number_size_negative f_type_size_32_negative
+
+ #define f_type_number_size_max_unsigned f_type_size_max_32_unsigned
+ #define f_type_number_size_max_positive f_type_size_max_32_positive
+ #define f_type_number_size_max_negative f_type_size_max_32_negative
+#endif // _en_f_type_number_32_
+
+#ifdef _en_f_type_number_128_
+ typedef f_int_128 f_number_signed;
+ typedef f_uint_128 f_number_unsigned;
+
+ #define f_type_number_size_unsigned f_type_size_128_unsigned
+ #define f_type_number_size_positive f_type_size_128_positive
+ #define f_type_number_size_negative f_type_size_128_negative
+
+ #define f_type_number_size_max_unsigned f_type_size_max_128_unsigned
+ #define f_type_number_size_max_positive f_type_size_max_128_positive
+ #define f_type_number_size_max_negative f_type_size_max_128_negative
+#endif // _en_f_type_number_128_
+
+/**
* Standard Input/Output types.
*
* For most systems, there is no standard warning nor is there a standard debug.
* Defines a variable to be used by arrays.
*/
#ifndef _di_f_array_length_
- typedef uint64_t f_array_length;
- typedef uint32_t f_array_length_short;
- typedef f_int_128 f_array_length_long;
+ typedef f_number_unsigned f_array_length;
#endif // _di_f_array_length_
/**
#define f_macro_utf_character_to_char_1(character) (((character) & f_utf_character_mask_char_1) >> 24) // grab first byte.
#define f_macro_utf_character_to_char_2(character) (((character) & f_utf_character_mask_char_2) >> 16) // grab second byte.
- #define f_macro_utf_character_to_char_3(character) (((character) & f_utf_character_mask_char_3) >> 8) // grab third byte.
- #define f_macro_utf_character_to_char_4(character) ((character) & f_utf_character_mask_char_4) // grab fourth byte.
+ #define f_macro_utf_character_to_char_3(character) (((character) & f_utf_character_mask_char_3) >> 8) // grab third byte.
+ #define f_macro_utf_character_to_char_4(character) ((character) & f_utf_character_mask_char_4) // grab fourth byte.
#define f_macro_utf_character_from_char_1(character) ((character) << 24) // shift the first byte.
#define f_macro_utf_character_from_char_2(character) ((character) << 16) // shift the second byte.
- #define f_macro_utf_character_from_char_3(character) ((character) << 8) // shift the third byte.
- #define f_macro_utf_character_from_char_4(character) ((character)) // shift the fourth byte.
+ #define f_macro_utf_character_from_char_3(character) ((character) << 8) // shift the third byte.
+ #define f_macro_utf_character_from_char_4(character) ((character)) // shift the fourth byte.
- #define f_macro_utf_character_width(character) (f_macro_utf_byte_width(f_macro_utf_character_to_char_1(character)))
+ #define f_macro_utf_character_width(character) (f_macro_utf_byte_width(f_macro_utf_character_to_char_1(character)))
#define f_macro_utf_character_width_is(character) (f_macro_utf_byte_width_is(f_macro_utf_character_to_char_1(character)))
#endif // _di_f_utf_character_
#ifndef _di_f_utf_string_
typedef f_utf_character *f_utf_string;
- #define f_utf_string_max_size f_type_size_32_signed
+ #define f_utf_string_max_size f_type_number_size_unsigned
#define f_utf_string_initialize f_utf_character_eos
#define f_macro_utf_string_new(status, string, length) status = f_memory_new((void **) & string, sizeof(f_utf_string), length)
* Provide a type specifically for UTF-8 strings.
*/
#ifndef _di_f_utf_string_length_
- typedef long f_utf_string_length;
+ typedef f_number_unsigned f_utf_string_length;
#define f_macro_utf_string_length_new(status, string, length) status = f_memory_new((void **) & string, sizeof(f_utf_string_length), length)
#ifndef _di_f_utf_string_lengths_
typedef struct {
f_utf_string_length *array;
- f_array_length size;
- f_array_length used;
+
+ f_array_length size;
+ f_array_length used;
} f_utf_string_lengths;
#define f_utf_string_lengths_initialize { 0, 0, 0 }
#ifndef _di_f_utf_string_locations_
typedef struct {
f_utf_string_location *array;
- f_array_length size;
- f_array_length used;
+
+ f_array_length size;
+ f_array_length used;
} f_utf_string_locations;
#define f_utf_string_locations_initialize {0, 0, 0}
*/
#ifndef _di_f_utf_string_dynamic_
typedef struct {
- f_utf_string string;
+ f_utf_string string;
+
f_utf_string_length size;
f_utf_string_length used;
} f_utf_string_dynamic;
#ifndef _di_f_utf_string_dynamics_
typedef struct {
f_utf_string_dynamic *array;
- f_utf_string_length size;
- f_utf_string_length used;
+
+ f_utf_string_length size;
+ f_utf_string_length used;
} f_utf_string_dynamics;
#define f_utf_string_dynamics_initialize { 0, 0, 0 }
#endif
#ifndef _fl_console_parameter_to_number_signed_
- f_return_status fl_console_parameter_to_number_signed(const f_string argument, int64_t *number) {
+ f_return_status fl_console_parameter_to_number_signed(const f_string argument, f_number_signed *number) {
#ifndef _di_level_0_parameter_checking_
if (argument == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_f
#endif // _fl_console_parameter_to_number_signed_
#ifndef _fl_console_parameter_to_number_unsigned_
- f_return_status fl_console_parameter_to_number_unsigned(const f_string argument, uint64_t *number) {
+ f_return_status fl_console_parameter_to_number_unsigned(const f_string argument, f_number_unsigned *number) {
#ifndef _di_level_0_parameter_checking_
if (argument == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_f
#endif
/**
- * Convert a console parameter additional argument to a signed 64-bit integer.
+ * Convert a console parameter additional argument to a signed integer.
*
* This will detect based types as follows:
* - hexidecimals begin with either '0x' or '0X'.
* @see f_conversion_string_to_number_signed()
*/
#ifndef _fl_console_parameter_to_number_signed_
- f_return_status fl_console_parameter_to_number_signed(const f_string argument, int64_t *number);
+ f_return_status fl_console_parameter_to_number_signed(const f_string argument, f_number_signed *number);
#endif // _fl_console_parameter_to_number_signed_
/**
- * Convert a console parameter additional argument to an unsigned 64-bit integer.
+ * Convert a console parameter additional argument to an unsigned integer.
*
* This will detect based types as follows:
* - hexidecimals begin with either '0x' or '0X'.
* @see f_conversion_string_to_number_unsigned()
*/
#ifndef _fl_console_parameter_to_number_unsigned_
- f_return_status fl_console_parameter_to_number_unsigned(const f_string argument, uint64_t *number);
+ f_return_status fl_console_parameter_to_number_unsigned(const f_string argument, f_number_unsigned *number);
#endif // _fl_console_parameter_to_number_unsigned_
/**