commit a7e718ed6521a9cecff535f362feaa185c56748c Author: Ammerhai Date: Mon May 27 14:10:08 2024 +0200 init taschenrechner and calendar diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8962e47 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +Taschenrechner/Debug +Taschenrechner/x64 +x64/Debug/Taschenrechner.ilk diff --git a/Taschenrechner.sln b/Taschenrechner.sln new file mode 100644 index 0000000..3eda3a7 --- /dev/null +++ b/Taschenrechner.sln @@ -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 diff --git a/Taschenrechner/Help.txt b/Taschenrechner/Help.txt new file mode 100644 index 0000000..c687345 --- /dev/null +++ b/Taschenrechner/Help.txt @@ -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 + diff --git a/Taschenrechner/Main.cpp b/Taschenrechner/Main.cpp new file mode 100644 index 0000000..1b9fd41 --- /dev/null +++ b/Taschenrechner/Main.cpp @@ -0,0 +1,316 @@ +#include +#include +#include +//#include "math_graphics.h" +#include +#include +#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; +} \ No newline at end of file diff --git a/Taschenrechner/Taschenrechner.vcxproj b/Taschenrechner/Taschenrechner.vcxproj new file mode 100644 index 0000000..66b92ec --- /dev/null +++ b/Taschenrechner/Taschenrechner.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {30C8FA23-4830-483D-865C-7F27771D9A73} + Taschenrechner + 10.0 + + + + Application + true + ClangCL + MultiByte + + + Application + false + ClangCL + true + MultiByte + + + Application + true + ClangCL + MultiByte + + + Application + false + ClangCL + true + MultiByte + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + .exe + + + false + .exe + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + false + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + false + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + false + false + + + Console + true + true + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + false + false + + + Console + true + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Taschenrechner/Taschenrechner.vcxproj.filters b/Taschenrechner/Taschenrechner.vcxproj.filters new file mode 100644 index 0000000..62a88fb --- /dev/null +++ b/Taschenrechner/Taschenrechner.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Quelldateien + + + + + Headerdateien + + + Headerdateien + + + + + + \ No newline at end of file diff --git a/Taschenrechner/Taschenrechner.vcxproj.user b/Taschenrechner/Taschenrechner.vcxproj.user new file mode 100644 index 0000000..966b4ff --- /dev/null +++ b/Taschenrechner/Taschenrechner.vcxproj.user @@ -0,0 +1,6 @@ + + + + true + + \ No newline at end of file diff --git a/Taschenrechner/m_string.h b/Taschenrechner/m_string.h new file mode 100644 index 0000000..f469de4 --- /dev/null +++ b/Taschenrechner/m_string.h @@ -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; +} \ No newline at end of file diff --git a/Taschenrechner/math_graphics.h b/Taschenrechner/math_graphics.h new file mode 100644 index 0000000..628e54c --- /dev/null +++ b/Taschenrechner/math_graphics.h @@ -0,0 +1,699 @@ +#pragma once + +#include +#include +#include +#include +#include + +//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 +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); +} \ No newline at end of file diff --git a/Tokenizer.cpp b/Tokenizer.cpp new file mode 100644 index 0000000..e69de29 diff --git a/calender.py b/calender.py new file mode 100644 index 0000000..528fb51 --- /dev/null +++ b/calender.py @@ -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) \ No newline at end of file diff --git a/x64/Debug/Taschenrechner.exe b/x64/Debug/Taschenrechner.exe new file mode 100644 index 0000000..d46823d Binary files /dev/null and b/x64/Debug/Taschenrechner.exe differ diff --git a/x64/Debug/Taschenrechner.pdb b/x64/Debug/Taschenrechner.pdb new file mode 100644 index 0000000..c243e74 Binary files /dev/null and b/x64/Debug/Taschenrechner.pdb differ diff --git a/x64/Release/Taschenrechner.exe b/x64/Release/Taschenrechner.exe new file mode 100644 index 0000000..0b0dff5 Binary files /dev/null and b/x64/Release/Taschenrechner.exe differ diff --git a/x64/Release/Taschenrechner.pdb b/x64/Release/Taschenrechner.pdb new file mode 100644 index 0000000..6bbe5bb Binary files /dev/null and b/x64/Release/Taschenrechner.pdb differ