BAN: Add math to its own namespace

This commit is contained in:
Bananymous 2023-01-10 19:11:27 +02:00
parent 181478119e
commit 6f9552d673
9 changed files with 32 additions and 16 deletions

View File

@ -5,7 +5,6 @@
#include <BAN/String.h>
#include <BAN/StringView.h>
#include <assert.h>
#include <string.h>
namespace BAN
@ -200,7 +199,7 @@ namespace BAN
{
if (m_capasity >= size)
return {};
size_type new_cap = BAN::max<size_type>(size, m_capasity * 1.5f);
size_type new_cap = BAN::Math::max<size_type>(size, m_capasity * 1.5f);
void* new_data = BAN::allocator(new_cap);
if (new_data == nullptr)
return Error::FromString("String: Could not allocate memory");

View File

@ -2,7 +2,6 @@
#include <BAN/StringView.h>
#include <BAN/Vector.h>
#include <assert.h>
#include <string.h>
namespace BAN

View File

@ -1,6 +1,7 @@
#pragma once
#include <assert.h>
#include <BAN/Errors.h>
#include <stddef.h>
namespace BAN

View File

@ -1,6 +1,6 @@
#pragma once
namespace BAN
namespace BAN::Math
{
template<typename T>
@ -21,4 +21,23 @@ namespace BAN
return x < min ? min : x > max ? max : x;
}
template<typename T>
T gcd(T a, T b)
{
T t;
while (b)
{
t = b;
b = a % b;
a = t;
}
return a;
}
template<typename T>
T lcm(T a, T b)
{
return a / gcd(a, b) * b;
}
}

View File

@ -9,11 +9,11 @@
namespace BAN
{
#if defined(__is_kernel)
static constexpr auto& allocator = kmalloc;
static constexpr auto& deallocator = kfree;
static constexpr void*(&allocator)(size_t) = kmalloc;
static constexpr void(&deallocator)(void*) = kfree;
#else
static constexpr auto& allocator = malloc;
static constexpr auto& deallocator = free;
static constexpr void*(&allocator)(size_t) = malloc;
static constexpr void(&deallocator)(void*) = free;
#endif
template<typename T>

View File

@ -4,7 +4,6 @@
#include <BAN/Math.h>
#include <BAN/Memory.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
@ -96,7 +95,7 @@ namespace BAN
if (m_capacity > size)
return {};
size_type new_cap = BAN::max<size_type>(m_capacity * 1.5f, m_capacity + 1);
size_type new_cap = BAN::Math::max<size_type>(m_capacity * 1.5f, m_capacity + 1);
void* new_data = BAN::allocator(new_cap * sizeof(T));
if (new_data == nullptr)
return Error::FromString("Queue: Could not allocate memory");

View File

@ -4,7 +4,6 @@
#include <BAN/Math.h>
#include <BAN/Memory.h>
#include <assert.h>
#include <string.h>
namespace BAN
@ -208,7 +207,7 @@ namespace BAN
{
if (m_capasity >= size)
return {};
size_type new_cap = BAN::max<size_type>(size, m_capasity * 1.5f);
size_type new_cap = BAN::Math::max<size_type>(size, m_capasity * 1.5f);
void* new_data = BAN::allocator(new_cap * sizeof(T));
if (new_data == nullptr)
return Error::FromString("Vector: Could not allocate memory");

View File

@ -113,7 +113,6 @@ _start:
orl $0x80000000, %ecx
movl %ecx, %cr0
xchgw %bx, %bx
# call global constuctors
call _init
@ -121,6 +120,7 @@ _start:
call kernel_main
system_halt:
xchgw %bx, %bx
cli
1: hlt
jmp 1b

View File

@ -282,8 +282,8 @@ namespace Kernel
{
m_mouse_pos.exists = true;
m_tty->RenderFromBuffer(m_mouse_pos.x, m_mouse_pos.y);
m_mouse_pos.x = clamp<int32_t>(m_mouse_pos.x + event.dx, 0, m_tty->Width() - 1);
m_mouse_pos.y = clamp<int32_t>(m_mouse_pos.y - event.dy, 0, m_tty->Height() - 1);
m_mouse_pos.x = Math::clamp<int32_t>(m_mouse_pos.x + event.dx, 0, m_tty->Width() - 1);
m_mouse_pos.y = Math::clamp<int32_t>(m_mouse_pos.y - event.dy, 0, m_tty->Height() - 1);
VESA::PutBitmapAt(s_pointer, m_mouse_pos.x, m_mouse_pos.y, VESA::Color::BRIGHT_WHITE);
}