serenity/AK
Daniel Bertalan c6fafd3e90 AK+Userland: Add generic AK::abs() function and use it
Previously, in LibGFX's `Point` class, calculated distances were passed
to the integer `abs` function, even if the stored type was a float. This
caused the value to unexpectedly be truncated. Luckily, this API was not
used with floating point types, but that can change in the future, so
why not fix it now :^)

Since we are in C++, we can use function overloading to make things
easy, and to automatically use the right version.

This is even better than the LibC/LibM functions, as using a bit of
hackery, they are able to be constant-evaluated. They use compiler
intrinsics, so they do not depend on external code and the compiler can
emit the most optimized code by default.

Since we aren't using the C++ standard library's trick of importing
everything into the `AK` namespace, this `abs` function cannot be
exported to the global namespace, as the names would clash.
2021-07-08 10:11:00 +02:00
..
AllOf.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
AnyOf.h AK: Reimplement any_of in terms of find_if 2021-06-20 10:54:09 +01:00
Array.h AK: Export integer_sequence_generate_array() 2021-05-05 19:02:51 +02:00
Assertions.h LibC+AK: Remove our custom macros from <assert.h> 2021-06-08 17:29:57 +02:00
Atomic.h AK: Specialize Atomic<Integral> for clang compatibility 2021-06-24 17:35:49 +04:30
Badge.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Base64.cpp Meta: Disable -Wmaybe-uninitialized 2021-06-09 23:05:32 +04:30
Base64.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
BinaryHeap.h AK+Userland: Use idan.horowitz@serenityos.org for my copyright headers 2021-04-22 22:42:38 +02:00
BinarySearch.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
BitCast.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Bitmap.h Bitmap: De-duplicate bitmasks 2021-05-19 23:37:10 +01:00
BitmapView.h Bitmap: De-duplicate bitmasks 2021-05-19 23:37:10 +01:00
BitStream.h AK: Add big endian bit reading to InputBitStream 2021-06-25 20:48:14 +04:30
Buffered.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ByteBuffer.h AK: Add ByteBuffer::append(ReadonlyBytes) 2021-06-12 22:45:01 +04:30
ByteReader.h LibCrypto+LibTLS: Avoid unaligned reads and writes 2021-05-14 08:39:29 +01:00
CharacterTypes.h AK: Add the to_ascii_base36_digit helper method 2021-06-29 16:55:54 +01:00
Checked.h AK: Explicitly require Checked types to be Integral 2021-07-04 20:08:28 +01:00
CheckedFormatString.h AK+Everywhere: Fix compiletime format parsing of replacement fields 2021-06-01 23:12:17 +04:30
CircularDeque.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CircularDuplexStream.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CircularQueue.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CMakeLists.txt Meta: Add support for declaring components 2021-06-17 11:03:51 +02:00
Complex.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Concepts.h AK+LibIPC: Make all enums codable 2021-07-04 13:48:20 +04:30
Debug.h.in Meta: Remove the LibJS OBJECT_DEBUG debug macro 2021-07-04 22:07:36 +01:00
Demangle.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
DistinctNumeric.h AK: Make DistinctNumeric constexpr-capable 2021-05-04 21:32:15 +02:00
DoublyLinkedList.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Endian.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
EnumBits.h Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
ExtraMathConstants.h Userland: Move non-standard math constants from math.h 2021-04-27 23:06:16 +02:00
FileStream.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Find.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
FlyString.cpp AK: Add a way to disable the trimming of whitespace in to_*int 2021-06-18 19:18:15 +01:00
FlyString.h AK: Add a way to disable the trimming of whitespace in to_*int 2021-06-18 19:18:15 +01:00
Format.cpp AK: Replace usages of ctype.h with CharacterTypes.h 2021-07-07 14:05:56 +02:00
Format.h AK: Support long doubles in format strings 2021-07-02 19:50:43 +02:00
Forward.h AK: Use OrderedHashMap in JsonObject 2021-06-29 13:18:03 +02:00
Function.h AK+Kernel: Fix perfect forwarding constructors shadowing others 2021-07-08 10:11:00 +02:00
GenericLexer.cpp AK/GenericLexer: constexpr where possible 2021-04-22 20:27:21 +02:00
GenericLexer.h AK/GenericLexer: constexpr where possible 2021-04-22 20:27:21 +02:00
HashFunctions.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
HashMap.h AK: Add a missing using AK::OrderedHashMap statement 2021-06-15 23:51:20 +01:00
HashTable.h AK: Add Ordering support to HashTable and HashMap 2021-06-15 22:16:55 +02:00
Hex.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Hex.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
IDAllocator.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
IntrusiveList.h AK+Tests: Add IntrusiveList<T,...>::insert_before(..) method 2021-06-16 10:40:01 +02:00
IntrusiveRedBlackTree.h Revert "AK: Remove virtual destructors from non-virtual classes" 2021-04-23 10:26:14 +02:00
IPv4Address.h AK: Implement IPv4Address::to_string_reversed() 2021-06-09 17:43:32 +04:30
IterationDecision.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Iterator.h AK: Make Vector capable of holding reference types 2021-06-08 19:14:24 +02:00
JsonArray.h AK: Use [[nodiscard]] in JsonObject and JsonArray 2021-06-29 13:18:03 +02:00
JsonArraySerializer.h Kernel: Don't compile JsonValue & friends into the kernel 2021-06-30 11:31:12 +02:00
JsonObject.h AK: Use [[nodiscard]] in JsonObject and JsonArray 2021-06-29 13:18:03 +02:00
JsonObjectSerializer.h Kernel: Don't compile JsonValue & friends into the kernel 2021-06-30 11:31:12 +02:00
JsonParser.cpp JsonParser: Bring parser more to spec 2021-07-05 12:36:19 +02:00
JsonParser.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
JsonPath.cpp Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
JsonPath.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
JsonValue.cpp Kernel+AK: Don't compile JSON parser into the kernel 2021-06-29 22:19:29 +02:00
JsonValue.h AK: Make JsonValue::as_string_or() const 2021-06-29 13:18:03 +02:00
kmalloc.cpp AK: Declare operators new and delete as global functions 2021-07-05 20:23:42 +02:00
kmalloc.h AK: Declare operators new and delete as global functions 2021-07-05 20:23:42 +02:00
kstdio.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
LEB128.h AK: Handle LEB128 encoded values that are too large for the result type 2021-05-31 14:25:27 +04:30
LexicalPath.cpp AK+Everywhere: Remove StringView::find_{first,last}_of(char) methods 2021-07-02 21:54:21 +02:00
LexicalPath.h AK: Use canonicalized_path in LexicalPath::relative_path 2021-06-30 11:13:54 +02:00
MACAddress.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
MappedFile.cpp AK: Rename adopt() to adopt_ref() 2021-04-23 16:46:57 +02:00
MappedFile.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
MemMem.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Memory.h AK: Guard inline assembly with ARCH(I386) and provide alternative 2021-05-31 17:29:09 +01:00
MemoryStream.h Kernel+LibC: Make get_dir_entries syscall retriable 2021-05-12 12:50:23 +02:00
NeverDestroyed.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Noncopyable.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
NonnullOwnPtr.h AK: Make smart pointer factories work with aggregates 2021-07-03 01:56:31 +04:30
NonnullOwnPtrVector.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
NonnullPtrVector.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
NonnullRefPtr.h AK: Make smart pointer factories work with aggregates 2021-07-03 01:56:31 +04:30
NonnullRefPtrVector.h AK: Make NonnullRefPtrVector constructible from Vector<NonnullRefPtr> 2021-06-11 00:30:09 +02:00
NumberFormat.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
NumericLimits.h AK/NumericLimits: Add lowest() for floating-point types 2021-05-22 13:38:34 +01:00
Optional.h AK: Use conditionally trivial special member functions 2021-07-04 07:24:41 +04:30
OSError.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
OwnPtr.h AK: Make smart pointer factories work with aggregates 2021-07-03 01:56:31 +04:30
Platform.h Kernel: Replace raw asm functions with naked ones 2021-07-05 16:40:00 +02:00
PrintfImplementation.h AK: Honor variable precision argument when formatting 2021-05-30 18:45:06 +01:00
Ptr32.h AK: Fix building Ptr32 on x86_64 2021-06-24 09:27:13 +02:00
Queue.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
QuickSort.h AK: Guarantee a maximum stack depth for dual_pivot_quick_sort 2021-04-28 21:38:48 +02:00
Random.cpp AK: Introduce get_random_uniform() 2021-05-14 22:24:02 +02:00
Random.h AK: Introduce get_random_uniform() 2021-05-14 22:24:02 +02:00
RedBlackTree.h AK: Add RedBlackTree::find_largest_not_above_iterator 2021-06-19 14:51:18 +02:00
RefCounted.h AK: Allow inlining ref-count functionality 2021-06-03 08:06:51 +02:00
RefPtr.h AK: Make smart pointer factories work with aggregates 2021-07-03 01:56:31 +04:30
Result.h AK: Let Result<T, E> know its Value and Error types 2021-05-08 22:14:39 +02:00
ScopedValueRollback.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ScopeGuard.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ScopeLogger.h AK: Store the 'extra' field of ScopeLogger as String 2021-06-29 00:07:19 +04:30
SIMD.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Singleton.h LibCore+AK: Use proper atomics in Singleton 2021-06-24 17:35:49 +04:30
SinglyLinkedList.h AK: Add support for removing SinglyLinkedList nodes during iteration 2021-06-15 23:59:21 +01:00
SinglyLinkedListWithCount.h Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
SourceGenerator.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
SourceLocation.h AK+Userland: Use akaster@serenityos.org for my copyright headers 2021-05-30 14:35:34 +01:00
Span.h AK: Annotate more AK::Span methods as nodiscard 2021-07-01 22:44:06 +02:00
Stack.h AK: Implement AK::Stack 2021-05-26 16:36:53 +04:30
StackInfo.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
StackInfo.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
StdLibExtraDetails.h AK: Add type traits describing supported operations 2021-07-04 07:24:41 +04:30
StdLibExtras.h AK+Userland: Add generic AK::abs() function and use it 2021-07-08 10:11:00 +02:00
Stream.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
String.cpp AK: Add generation of roman numerals to AK::String 2021-07-04 22:17:03 +02:00
String.h AK: Add generation of roman numerals to AK::String 2021-07-04 22:17:03 +02:00
StringBuilder.cpp AK: Remove the m_length member for StringBuilder 2021-05-31 14:49:00 +04:30
StringBuilder.h AK: Remove the m_length member for StringBuilder 2021-05-31 14:49:00 +04:30
StringHash.h AK: Make StringView::hash() constexpr 2021-05-14 15:24:32 +02:00
StringImpl.cpp AK: Implement StringView::to_{lower,upper}case_string 2021-07-02 21:54:21 +02:00
StringImpl.h AK: Implement StringView::to_{lower,upper}case_string 2021-07-02 21:54:21 +02:00
StringUtils.cpp AK: Replace usages of ctype.h with CharacterTypes.h 2021-07-07 14:05:56 +02:00
StringUtils.h AK: Implement String::find_any_of() and StringView::find_any_of() 2021-07-02 21:54:21 +02:00
StringView.cpp AK: Implement String::find_any_of() and StringView::find_any_of() 2021-07-02 21:54:21 +02:00
StringView.h AK: Implement String::find_any_of() and StringView::find_any_of() 2021-07-02 21:54:21 +02:00
TemporaryChange.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Time.cpp Time: Remove static from function local constexpr variable 2021-05-19 16:24:02 +02:00
Time.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Traits.h AK: Add ConstPeekType to Traits 2021-05-08 18:10:56 +02:00
Trie.h AK: Add children() accessor to Trie 2021-06-08 12:15:04 +02:00
Tuple.h AK: Add deduction guides to Tuple 2021-05-18 18:48:15 +01:00
TypeCasts.h AK: Rename downcast<T> => verify_cast<T> 2021-06-24 19:57:01 +02:00
TypedTransfer.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
TypeList.h Everywhere: "indexes" => "indices" 2021-04-29 22:23:52 +02:00
Types.h Kernel: Fix memset() on x86_64 2021-06-28 15:55:00 +02:00
UBSanitizer.h Kernel+AK: Move UBSanitizer to AK, and to AK namespace 2021-05-27 15:18:03 +02:00
UFixedBigInt.h AK+LibX86: Generalize u128/256 to AK::UFixedBigInt 2021-06-11 18:14:11 +04:30
UnicodeUtils.cpp AK: Add UnicodeUtils with Unicode-related helper functions 2021-05-20 22:10:45 +02:00
UnicodeUtils.h AK: Add UnicodeUtils with Unicode-related helper functions 2021-05-20 22:10:45 +02:00
URL.cpp AK: Remove the LexicalPath::is_valid() API 2021-06-30 11:13:54 +02:00
URL.h AK: Move identity check from URL::operator==() to equals() 2021-06-01 12:23:16 +02:00
URLParser.cpp Userland: Allow building SerenityOS with -funsigned-char 2021-06-13 18:52:58 +02:00
URLParser.h AK: Make debugging URLParser easier 2021-06-05 10:53:31 +02:00
Userspace.h AK: Make C++ concepts support mandatory for compilers 2021-06-24 17:35:49 +04:30
Utf8View.cpp AK: Add the Utf8View::{contains, trim} helper methods 2021-06-16 20:05:18 +01:00
Utf8View.h AK: Add the Utf8View::{contains, trim} helper methods 2021-06-16 20:05:18 +01:00
Utf32View.h AK: Rename Utf32CodepointIterator => Utf32CodePointIterator 2021-06-01 09:46:19 +02:00
UUID.cpp AK+Userland: Fix some compiler warnings and make variables const-ref 2021-05-16 17:49:42 +02:00
UUID.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Variant.h AK: Destroy original value when assigning to Variant 2021-07-04 07:24:41 +04:30
Vector.h AK: Rename Vector::append(Vector) => Vector::extend(Vector) 2021-06-12 13:24:45 +02:00
Weakable.h Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
WeakPtr.h AK: Rename adopt() to adopt_ref() 2021-04-23 16:46:57 +02:00