init taschenrechner and calendar

This commit is contained in:
Ammerhai 2024-05-27 14:10:08 +02:00
commit a7e718ed65
15 changed files with 1360 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
Taschenrechner/Debug
Taschenrechner/x64
x64/Debug/Taschenrechner.ilk

31
Taschenrechner.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Taschenrechner", "Taschenrechner\Taschenrechner.vcxproj", "{30C8FA23-4830-483D-865C-7F27771D9A73}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{30C8FA23-4830-483D-865C-7F27771D9A73}.Debug|x64.ActiveCfg = Debug|x64
{30C8FA23-4830-483D-865C-7F27771D9A73}.Debug|x64.Build.0 = Debug|x64
{30C8FA23-4830-483D-865C-7F27771D9A73}.Debug|x86.ActiveCfg = Debug|Win32
{30C8FA23-4830-483D-865C-7F27771D9A73}.Debug|x86.Build.0 = Debug|Win32
{30C8FA23-4830-483D-865C-7F27771D9A73}.Release|x64.ActiveCfg = Release|x64
{30C8FA23-4830-483D-865C-7F27771D9A73}.Release|x64.Build.0 = Release|x64
{30C8FA23-4830-483D-865C-7F27771D9A73}.Release|x86.ActiveCfg = Release|Win32
{30C8FA23-4830-483D-865C-7F27771D9A73}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4430C4AD-7DB1-4C55-B01D-10F4108AA691}
EndGlobalSection
EndGlobal

25
Taschenrechner/Help.txt Normal file
View File

@ -0,0 +1,25 @@
Taschenrechner --- Help
Operator:
- Addition 'Ausdruck' + 'Ausdruck'
- Subtraktion 'Ausdruck' - 'Ausdruck'
- Multiplikation 'Ausdruck' * 'Ausdruck'
- Division 'Ausdruck' / 'Ausdruck'
- Potenzen 'Ausdruck' ^ 'Ausdruck'
Klammern:
('Ausdruck' + 'Ausdruck') * 'Ausdruck'
('Ausdruck' + 'Ausdruck') * ('Ausdruck' - 'Ausdruck')
'Ausdruck' - (('Ausdruck' + 'Ausdruck') * 'Ausdruck') / 'Ausdruck'
Trigonometrie:
- Wurzel sqrt 'Ausdruck' ODER sqrt('Ausdruck')
- Sinus/Cosinus/Tangens sin/cos/tan 'Ausdruck' ODER sin('Ausdruck')
Letzte Antwort kann mittels 'ans' genutzt werden. Beispiel:
- 4 + 5
9
- ans * 2
18

316
Taschenrechner/Main.cpp Normal file
View File

@ -0,0 +1,316 @@
#include <stdio.h>
#include <string.h>
#include <windows.h>
//#include "math_graphics.h"
#include <math.h>
#include <setjmp.h>
#include "m_string.h"
enum TokenKind {
ENDOFINPUT, INTEGER, KOMMA, PLUS, MINUS, MUL, DIV, MODULO, LPAREN, RPAREN, POW, SQRT, SIN, COS, TAN, ATAN, ATAN2, ANS
};
//Definition Token
struct Token {
TokenKind kind = ENDOFINPUT;
double floatValue;
long intValue;
};
//Erkennen ob Leerzeichen, Zeilenumbruch, Tabulator etc.
bool isWhitespace(char c) {
if (c == ' ' || c == '\n' || c == '\t' || c == '\r') {
return true;
}
return false;
}
//Wenn Whitsepace weitergehen
void eatWhitespace(String &s) {
while (isWhitespace(s[0])) {
advance(s);
}
}
bool isNumber(char c) {
if ('0' <= c && c <= '9') {
return true;
}
return false;
}
long parseInteger(String inputString) {
long integerValue = 0;
for (int currentPosition = 0; currentPosition < inputString.length; currentPosition++) {
integerValue = integerValue * 10 + inputString[currentPosition] - '0';
}
return integerValue;
}
double parseFloat(String inputString) {
double floatValue = 0.0;
int currentPosition = 0;
for (; currentPosition < inputString.length; currentPosition++) {
if (inputString[currentPosition] == '.') {
currentPosition++;
break;
}
floatValue = floatValue * 10.0 + (inputString[currentPosition] - '0');
}
double floatValue2 = 0.0;
for (int currentPosition2 = inputString.length - 1; currentPosition2 >= currentPosition; currentPosition2--) {
floatValue2 = floatValue2 / 10.0 + (inputString[currentPosition2] - '0');
}
return floatValue + (floatValue2 / 10);
}
//Funktion zur Erkennung neuer Token
Token getNextToken(String &inputString) {
Token token = {};
eatWhitespace(inputString);
if (!inputString.length) {
return token;
}
if (isNumber(inputString[0])) {
String start = inputString;
advance(inputString);
while (isNumber(inputString[0])) {
advance(inputString);
}
if (inputString[0] == '.') {
token.kind = KOMMA;
advance(inputString);
while (isNumber(inputString[0])) {
advance(inputString);
}
start.length = inputString.data - start.data;
token.floatValue = parseFloat(start);
} else {
start.length = inputString.data - start.data;
token.kind = INTEGER;
token.intValue = parseInteger(start);
}
//Token für mathematische Operatoren
//ergänzt werden müssen: "atan2"
} else if (inputString[0] == '+') {
token.kind = PLUS;
advance(inputString);
} else if (inputString[0] == '-') {
token.kind = MINUS;
advance(inputString);
} else if (inputString[0] == '*') {
token.kind = MUL;
advance(inputString);
} else if (inputString[0] == '/') {
token.kind = DIV;
advance(inputString);
} else if (inputString[0] == '%') {
token.kind = MODULO;
advance(inputString);
} else if (inputString[0] == '(') {
token.kind = LPAREN;
advance(inputString);
} else if (inputString[0] == ')') {
token.kind = RPAREN;
advance(inputString);
} else if (inputString[0] == '^') {
token.kind = POW;
advance(inputString);
} else if (starts_with(inputString, "atan2"_str)) {
token.kind = ATAN2;
advance(inputString, 5);
} else if (starts_with(inputString, "atan"_str)) {
token.kind = ATAN;
advance(inputString, 4);
} else if (starts_with(inputString, "sqrt"_str)) {
token.kind = SQRT;
advance(inputString, 4);
} else if (starts_with(inputString, "sin"_str)) {
token.kind = SIN;
advance(inputString, 3);
} else if (starts_with(inputString, "cos"_str)) {
token.kind = COS;
advance(inputString, 3);
} else if (starts_with(inputString, "tan"_str)) {
token.kind = TAN;
advance(inputString, 3);
} else if (starts_with(inputString, "ans"_str)) {
token.kind = ANS;
advance(inputString, 3);
}
return token;
}
double parseExpression(String &string);
Token token = {};
double ans = 0;
jmp_buf Rechner;
#define expect(k) if(token.kind != (k)) { printf("Unexpected Token"); exit(0); } token = getNextToken(input);
double parseExpressionOperand(String& input) {
if (token.kind == INTEGER) {
long value = token.intValue;
token = getNextToken(input);
return value;
} else if (token.kind == KOMMA) {
double value = token.floatValue;
token = getNextToken(input);
return value;
} else if (token.kind == LPAREN) {
token = getNextToken(input);
double expression = parseExpression(input);
expect(RPAREN);
return expression;
} else if (token.kind == SQRT) {
token = getNextToken(input);
return sqrt(parseExpressionOperand(input));
} else if (token.kind == SIN) {
token = getNextToken(input);
return sin(parseExpressionOperand(input));
} else if (token.kind == COS) {
token = getNextToken(input);
return cos(parseExpressionOperand(input));
} else if (token.kind == TAN) {
token = getNextToken(input);
return tan(parseExpressionOperand(input));
} else if (token.kind == ATAN) {
token = getNextToken(input);
return atan(parseExpressionOperand(input));
} else if (token.kind == ATAN2) {
printf("Coming soon!");
return 0;
} else if (token.kind == ANS) {
token = getNextToken(input);
return ans;
}
printf("Unexpected Token.\n");
longjmp(Rechner, 0);
return 0;
}
double parseExpressionUnary(String& input) {
if (token.kind == MINUS) {
token = getNextToken(input);
return -parseExpressionUnary(input);
}
return parseExpressionOperand(input);
}
double parseExpressionPower(String& input) {
double expression = parseExpressionUnary(input);
while (token.kind == POW) {
token = getNextToken(input);
expression = pow(expression, parseExpressionUnary(input));
}
return expression;
}
double parseExpressionMultiplicative(String& input) {
double expression = parseExpressionPower(input);
while (token.kind == MUL || token.kind == DIV) {
if (token.kind == MUL) {
token = getNextToken(input);
expression = expression * parseExpressionPower(input);
} else if (token.kind == DIV) {
token = getNextToken(input);
expression = expression / parseExpressionPower(input);
}
}
return expression;
}
double parseExpressionAdditive(String& input) {
double expression = parseExpressionMultiplicative(input);
while (token.kind == PLUS || token.kind == MINUS) {
if (token.kind == PLUS) {
token = getNextToken(input);
expression = expression + parseExpressionMultiplicative(input);
} else if (token.kind == MINUS) {
token = getNextToken(input);
expression = expression - parseExpressionMultiplicative(input);
}
}
return expression;
}
double parseExpression(String &input) {
return parseExpressionAdditive(input);
}
void write_entire_file(const char* filename, String s){
FILE* file = fopen(filename, "w");
fwrite(s.data, s.length, 1, file);
fclose(file);
}
String helpstring = R"(
Taschenrechner --- Help
Operator:
- Addition 'Ausdruck' + 'Ausdruck'
- Subtraktion 'Ausdruck' - 'Ausdruck'
- Multiplikation 'Ausdruck' * 'Ausdruck'
- Division 'Ausdruck' / 'Ausdruck'
- Potenzen 'Ausdruck' ^ 'Ausdruck'
Klammern:
('Ausdruck' + 'Ausdruck') * 'Ausdruck'
('Ausdruck' + 'Ausdruck') * ('Ausdruck' - 'Ausdruck')
'Ausdruck' - (('Ausdruck' + 'Ausdruck') * 'Ausdruck') / 'Ausdruck'
Trigonometrie:
- Wurzel sqrt 'Ausdruck' ODER sqrt('Ausdruck')
- Sinus/Cosinus/Tangens sin/cos/tan 'Ausdruck' ODER sin('Ausdruck')
Letzte Antwort kann mittels 'ans' genutzt werden. Beispiel:
- 4 + 5
9
- ans * 2
18
)"_str;
int main() {
SetConsoleOutputCP(65001);
write_entire_file("Help.txt", helpstring);
while (true) {
setjmp(Rechner);
printf("Was möchten Sie berechnen? Für Hilfe 'help' eingeben!\n");
char buffer[1024];
String input = { 1024, buffer };
fgets(buffer, 1024, stdin);
input.length = strlen(buffer);
if (starts_with(input, "help"_str) || starts_with(input, "Help"_str)) {
printf("%s", helpstring.data);
continue;
}
token = getNextToken(input);
ans = parseExpression(input);
printf("%g\n", ans);
}
return 0;
}

View File

@ -0,0 +1,161 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{30C8FA23-4830-483D-865C-7F27771D9A73}</ProjectGuid>
<RootNamespace>Taschenrechner</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ExceptionHandling>false</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ExceptionHandling>false</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="math_graphics.h" />
<ClInclude Include="m_string.h" />
</ItemGroup>
<ItemGroup>
<Text Include="Help.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Quelldateien">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Headerdateien">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Ressourcendateien">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="m_string.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="math_graphics.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="Help.txt" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>

39
Taschenrechner/m_string.h Normal file
View File

@ -0,0 +1,39 @@
#pragma once
struct String {
size_t length;
char* data;
char operator[](int index) {
if (index < 0) {
return 0;
}
if (index < length) {
return data[index];
}
return 0;
}
};
String operator""_str(const char* str, size_t length) {
return { length, (char*)str };
}
void advance(String &s, int num = 1) {
int to_advance = min(s.length, num);
s.data = s.data + to_advance;
s.length = s.length - to_advance;
}
bool starts_with(String s, String start) {
if (s.length < start.length) {
return false;
}
for (int i = 0; i < start.length; i++) {
if (s[i] != start[i]) {
return false;
}
}
return true;
}

View File

@ -0,0 +1,699 @@
#pragma once
#include <emmintrin.h>
#include <immintrin.h>
#include <xmmintrin.h>
#include <stdint.h>
#include <assert.h>
//clamp
constexpr inline float clamp(float min, float a, float max) {
float result = a;
if (a < min)
result = min;
if (a > max)
result = max;
return result;
}
//clamp für 0-1 Bereich (Grafik)
constexpr inline float clamp01(float a) {
return clamp(0, a, 1);
}
//wurzelberechnung
inline float square_root(float a) {
return _mm_cvtss_f32(_mm_sqrt_ss(_mm_set_ss(a)));
}
inline float reciprocal_square_root(float a) {
return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(a)));
}
constexpr inline float min(float a, float b) {
return a < b ? a : b;
}
constexpr inline float max(float a, float b) {
return a > b ? a : b;
}
constexpr inline double min(double a, double b) {
return a < b ? a : b;
}
constexpr inline double max(double a, double b) {
return a > b ? a : b;
}
constexpr inline int64_t min(int64_t a, int64_t b) {
return a < b ? a : b;
}
template<typename T>
constexpr inline T min(T a, T b) {
return a < b ? a : b;
}
constexpr float lerp(float a, float t, float b) {
return (1.0f - t) * a + t * b;
}
//-----------------------------------------------
//Vektorberechnung 2-dim
union V2 {
struct {
float x;
float y;
};
struct {
float u;
float v;
};
struct {
float width;
float height;
};
struct {
float E[2];
};
float operator [](size_t index) {
assert(index < 2);
return E[index];
}
};
//Negation von 2-dim Vektor
inline V2 operator -(V2 a) {
return {
-a.x,
-a.y
};
}
//Addition 2er 2-dim Vektoren
inline V2 operator +(V2 a, V2 b) {
return {
a.x + b.x,
a.y + b.y
};
}
//Subtraktion 2er 2-dim Vektoren
inline V2 operator -(V2 a, V2 b) {
return {
a.x - b.x,
a.y - b.y
};
}
//Skalarmultiplikation -> erst Skalar, dann Vektor
inline V2 operator *(float a, V2 b) {
return {
a * b.x,
a * b.y
};
}
//Skalarmultiplikation -> erst Vektor, dann Skalar
inline V2 operator *(V2 a, float b) {
return {
a.x * b,
a.y * b
};
}
//Division mit nem Skalar Oo -> Skalar geteilt durch Vektor
inline V2 operator /(float a, V2 b) {
return {
a / b.x,
a / b.y
};
}
//Division mit nem Skalar Oo -> Vektor geteilt durch Skalar
inline V2 operator /(V2 a, float b) {
return {
a.x / b,
a.y / b
};
}
//Skalarprodukt
inline float dot(V2 a, V2 b) {
return a.x * b.x + a.y * b.y;
}
//Hadamard-Produkt
inline V2 hadamard(V2 a, V2 b) {
return {
a.x * b.x,
a.y * b.y
};
}
//Betrag des Vektors quadrieren
inline float length_squared(V2 a) {
return dot(a, a);
}
//Betrag eines Vektors
inline float length(V2 a) {
return square_root(length_squared(a));
}
//Reziproke der Länge
inline float reciprocal_length(V2 a) {
return reciprocal_square_root(length_squared(a));
}
//Einheitsvektor
inline V2 normalize(V2 a) {
return a * reciprocal_length(a);
}
//Vektor der 90°
inline V2 perp(V2 a) {
return {
-a.y,
a.x
};
}
//clamp für 2-dim Vektor
inline V2 clamp01(V2 a) {
return {
clamp01(a.x),
clamp01(a.y)
};
}
inline V2 min(V2 a, V2 b) {
return {
min(a.x, b.x),
min(a.y, b.y),
};
}
inline V2 max(V2 a, V2 b) {
return {
max(a.x, b.x),
max(a.y, b.y),
};
}
inline float min(V2 a) {
return min(a.x, a.y);
}
inline float max(V2 a) {
return max(a.x, a.y);
}
//-----------------------------------------------
//Vektorberechnung 3-dim
union V3 {
struct {
float x;
float y;
float z;
};
//farbvektor
struct {
float r;
float g;
float b;
};
//texturvektor
struct {
float u;
float v;
float s;
};
//von V3 zu V2 ohne z
struct {
V2 xy;
float _z;
};
//von V3 zu V2 ohne x
struct {
float _x;
V2 yz;
};
struct {
float E[3];
};
float operator [](size_t index) {
assert(index < 3);
return E[index];
}
};
//Negation von 2-dim Vektor
inline V3 operator -(V3 a) {
return {
-a.x,
-a.y,
-a.z
};
}
//Addition 2er 2-dim Vektoren
inline V3 operator +(V3 a, V3 b) {
return {
a.x + b.x,
a.y + b.y,
a.z + b.z
};
}
//Subtraktion 2er 2-dim Vektoren
inline V3 operator -(V3 a, V3 b) {
return {
a.x - b.x,
a.y - b.y,
a.z - b.z
};
}
//Skalarmultiplikation -> erst Skalar, dann Vektor
inline V3 operator *(float a, V3 b) {
return {
a * b.x,
a * b.y,
a * b.z
};
}
//Skalarmultiplikation -> erst Vektor, dann Skalar
inline V3 operator *(V3 a, float b) {
return {
a.x * b,
a.y * b,
a.z * b
};
}
//Division mit nem Skalar Oo -> Skalar geteilt durch Vektor
inline V3 operator /(float a, V3 b) {
return {
a / b.x,
a / b.y,
a / b.z
};
}
//Division mit nem Skalar Oo -> Vektor geteilt durch Skalar
inline V3 operator /(V3 a, float b) {
return {
a.x / b,
a.y / b,
a.z / b
};
}
//Skalarprodukt
inline float dot(V3 a, V3 b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
//Hadamard-Produkt
inline V3 hadamard(V3 a, V3 b) {
return {
a.x * b.x,
a.y * b.y,
a.z * b.z
};
}
//Kreuzprodukt
inline V3 cross(V3 a, V3 b) {
return {
a.y * b.z - a.z * b.y,
a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x
};
}
//Betrag des Vektors quadrieren
inline float length_squared(V3 a) {
return dot(a, a);
}
//Betrag eines Vektors
inline float length(V3 a) {
return square_root(length_squared(a));
}
//Reziproke der Länge
inline float reciprocal_length(V3 a) {
return reciprocal_square_root(length_squared(a));
}
//Einheitsvektor
inline V3 normalize(V3 a) {
return a * reciprocal_length(a);
}
union V4 {
struct {
float x;
float y;
float z;
float w;
};
//farbvektor
struct {
float r;
float g;
float b;
float a;
};
//texturvektor
struct {
float u;
float v;
float s;
float t;
};
//von V3 zu V2 ohne z
struct {
V2 xy;
V2 zw;
};
//von V3 zu V2 ohne x
struct {
float _x;
V2 yz;
float _w;
};
struct {
float E[4];
};
V4(V2 a, V2 b) { xy = a; zw = b; }
V4(float a, float b, float c, float d) { x = a; y = b; z = c; w = d; }
V4(float a, float b, float c) { x = a; y = b; z = c; w = 1; }
V4() {}
float operator [](size_t index) {
assert(index < 4);
return E[index];
}
};
//-----------------------------------------------
//2x2 Matrix
//M2x2 m;
//m.E[0][1]
//m.V[1]
//m[1][0]
union M2x2 {
struct {
float x1; float x2;
float y1; float y2;
};
struct {
float E[2][2];
};
struct {
V2 V[2];
};
V2 &operator [](size_t index) {
assert(index < 2);
return V[index];
}
};
//Matrix negieren
inline M2x2 operator -(M2x2 a){
return {
-a[0][0], -a[0][1],
-a[1][0], -a[1][1]
};
}
//Matrix Addition
inline M2x2 operator +(M2x2 a, M2x2 b) {
return {
a[0][0] + b[0][0], a[0][1] + b[0][1],
a[1][0] + b[1][0], a[1][1] + b[1][1]
};
}
//Matrix Subtraktion
inline M2x2 operator -(M2x2 a, M2x2 b) {
return {
a[0][0] - b[0][0], a[0][1] - b[0][1],
a[1][0] - b[1][0], a[1][1] - b[1][1]
};
}
//Matrix Skalarmultiplikation
inline M2x2 operator *(M2x2 a, float b) {
return {
a[0][0] * b, a[0][1] * b,
a[1][0] * b, a[1][1] * b
};
}
//Matrix Skalarmultiplikation
inline M2x2 operator *(float a, M2x2 b) {
return {
a * b[0][0], a * b[0][1],
a * b[1][0], a * b[1][1]
};
}
//Matrix Multiplikation
inline M2x2 operator *(M2x2 a, M2x2 b) {
return {
a[0][0] * b[0][0] + a[0][1] * b[1][0], a[0][0] * b[0][1] + a[0][1] * b[1][1],
a[1][0] * b[0][0] + a[1][1] * b[1][0], a[1][0] * b[0][1] + a[1][1] * b[1][1]
};
}
//Matrix * Vektor
inline V2 operator *(M2x2 a, V2 b) {
return {
a[0][0] * b[0] + a[0][1] * b[1],
a[1][0] * b[0] + a[1][1] * b[1],
};
}
//Matrix Transponieren
inline M2x2 transpose(M2x2 a) {
return {
a[0][0], a[1][0],
a[0][1], a[1][1]
};
}
//Einheitsmatrix (oder Identitätsmatrix)
constexpr inline M2x2 identityM2x2() {
return {
1.0f, 0.0f,
0.0f, 1.0f
};
}
//-----------------------------------------------
//3x3 Matrix
union M3x3 {
struct {
float x1; float x2; float x3;
float y1; float y2; float y3;
float z1; float z2; float z3;
};
struct {
float E[3][3];
};
struct {
V3 V[3];
};
V3& operator [](size_t index) {
assert(index < 3);
return V[index];
}
};
//Matrix negieren
inline M3x3 operator -(M3x3 a) {
return {
-a[0][0], -a[0][1], -a[0][1],
-a[1][0], -a[1][1], -a[1][2],
-a[2][0], -a[2][1], -a[2][2]
};
}
//Matrix Addition
inline M3x3 operator +(M3x3 a, M3x3 b) {
return {
a[0][0] + b[0][0], a[0][1] + b[0][1], a[0][2] + b[0][2],
a[1][0] + b[1][0], a[1][1] + b[1][1], a[1][2] + b[1][2],
a[2][0] + b[2][0], a[2][1] + b[2][1], a[2][2] + b[2][2]
};
}
//Matrix Subtraktion
inline M3x3 operator -(M3x3 a, M3x3 b) {
return {
a[0][0] - b[0][0], a[0][1] - b[0][1], a[0][2] - b[0][2],
a[1][0] - b[1][0], a[1][1] - b[1][1], a[1][2] - b[1][2],
a[2][0] - b[2][0], a[2][1] - b[2][1], a[2][2] - b[2][2]
};
}
//Matrix Skalarmultiplikation
inline M3x3 operator *(M3x3 a, float b) {
return {
a[0][0] * b, a[0][1] * b, a[0][2] * b,
a[1][0] * b, a[1][1] * b, a[1][2] * b,
a[2][0] * b, a[2][1] * b, a[2][2] * b
};
}
//Matrix Skalarmultiplikation
inline M3x3 operator *(float a, M3x3 b) {
return {
a * b[0][0], a * b[0][1], a * b[0][2],
a * b[1][0], a * b[1][1], a * b[1][2],
a * b[2][0], a * b[2][1], a * b[2][2]
};
}
//Matrix Multiplikation
inline M3x3 operator *(M3x3 a, M3x3 b) {
return {
a[0][0] * b[0][0] + a[0][1] * b[1][0] + a[0][2] * b[2][0], a[0][0] * b[0][1] + a[0][1] * b[1][1] + a[0][2] * b[2][1], a[0][0] * b[0][2] + a[0][1] * b[1][2] + a[0][2] * b[2][2],
a[1][0] * b[0][0] + a[1][1] * b[1][0] + a[1][2] * b[2][0], a[1][0] * b[0][1] + a[1][1] * b[1][1] + a[1][2] * b[2][1], a[1][0] * b[0][2] + a[1][1] * b[1][2] + a[0][2] * b[2][2],
a[2][0] * b[0][0] + a[2][1] * b[1][0] + a[2][2] * b[2][0], a[2][0] * b[0][1] + a[2][1] * b[1][1] + a[2][2] * b[2][1], a[2][0] * b[0][2] + a[2][1] * b[1][2] + a[0][2] * b[2][2]
};
}
//Matrix * V2
inline V2 operator *(M3x3 a, V2 b) {
return {
b.x * a[0][0] + b.y * a[0][1] + 1.0f * a[0][2],
b.x * a[1][0] + b.y * a[1][1] + 1.0f * a[1][2],
};
}
//Matrix * V3
inline V3 operator *(M3x3 a, V3 b) {
return {
b.x * a[0][0] + b.y * a[0][1] + b.z * a[0][2],
b.x * a[1][0] + b.y * a[1][1] + b.z * a[1][2],
b.x * a[2][0] + b.y * a[2][1] + b.z * a[2][2]
};
}
//Matrix transponieren
inline M3x3 transpose(M3x3 a) {
return {
a[0][0], a[1][0], a[2][0],
a[0][1], a[1][1], a[2][1],
a[0][2], a[1][2], a[2][2]
};
}
//Einheitsmatrix (oder Identitätsmatrix)
inline M3x3 identityM3x3() {
return {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
};
}
//-----------------------------------------------
//m128i
struct m128i {
__m128i val;
};
inline __m128i operator &(m128i a, m128i b) {
return _mm_and_si128(a.val, b.val);
}
inline __m128i operator |(m128i a, m128i b) {
return _mm_or_si128(a.val, b.val);
}
inline __m128i operator >>(m128i a, int b) {
return _mm_srli_epi32(a.val, b);
}
inline __m128i operator <<(m128i a, int b) {
return _mm_slli_epi32(a.val, b);
}
//-----------------------------------------------
//m128
struct m128 {
__m128 val;
};
inline __m128 operator +(m128 a, m128 b) {
return _mm_mul_ps(a.val, b.val);
}
inline __m128 operator *(m128 a, m128 b) {
return _mm_mul_ps(a.val, b.val);
}
inline __m128 operator *(float a, m128 b) {
return _mm_mul_ps(_mm_set1_ps(a), b.val);
}
inline __m128 square_root(__m128 a) {
return _mm_sqrt_ps(a);
}
inline __m128 operator /(m128 a, m128 b) {
return _mm_div_ps(a.val, b.val);
}
inline __m128 lerp(__m128 a, float t, float b) {
return (1.0f - t) * a + (t * b);
}

0
Tokenizer.cpp Normal file
View File

47
calender.py Normal file
View File

@ -0,0 +1,47 @@
#Kalender.py
import calendar
from datetime import date
month_name = ["Januar", "Februar", "Maerz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]
# Definition Schaltjahr
def leap_year(year):
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
# Definition Anzahl Tage pro Monat
def days_leap_day(year, month):
days_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days = days_per_month[month - 1]
if month == 2 and leap_year(year):
days += 1
return days
# Calculate the calendar week number (ISO 8601)
def calendar_week(year, month, day):
d = date(year, month, day)
return d.isocalendar()[1]
# Definition Ausgabe
def calender(year):
for m in range(1, 13):
print(f"{month_name[m-1]} {year}".center(28))
print("KW MO DI MI DO FR SA SO")
month_calendar = calendar.monthcalendar(year, m)
for week in month_calendar:
# Check if the week contains days from the current month
if all(day == 0 for day in week):
continue
# Get the correct week number
week_num = calendar_week(year, m, next(day for day in week if day != 0))
print(f"{week_num:2}", end=" ")
for day in week:
if day == 0:
print(" ", end="")
else:
print(f"{day:2} ", end="")
print()
print()
calender(2024)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.