diff --git a/.CIclang/.clang-format b/.CIclang/.clang-format new file mode 100644 index 0000000..e2cbc59 --- /dev/null +++ b/.CIclang/.clang-format @@ -0,0 +1,245 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: WebKit +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: true +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +... \ No newline at end of file diff --git a/.CIclang/.github/dependabot.yml b/.CIclang/.github/dependabot.yml new file mode 100644 index 0000000..355e687 --- /dev/null +++ b/.CIclang/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.CIclang/.github/workflows/build-and-lint.yml b/.CIclang/.github/workflows/build-and-lint.yml new file mode 100644 index 0000000..a2c12fd --- /dev/null +++ b/.CIclang/.github/workflows/build-and-lint.yml @@ -0,0 +1,14 @@ +name: Build and lint + +on: + - push + - pull_request + +jobs: + build-and-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Check format + run: | + find . -path ./build -prune -o -type f -name '*.[c|h]' -print | xargs clang-format-18 --style=file --dry-run -Werror diff --git a/n1/binRepresent.c b/n1/binRepresent.c new file mode 100644 index 0000000..7460aca --- /dev/null +++ b/n1/binRepresent.c @@ -0,0 +1,104 @@ +#include +#include +#include + +void binPrint(int num[]) +{ + for (int i = 0; i < 32; i++) { + printf("%d", num[i]); + } + printf("\n"); +} + +int* bin(int number) +{ + + int num = number; + int* binary = (int*)malloc(32 * sizeof(int)); + if (number < 0) { + num *= -1; + } + int ind = 31; + + while (num != 0) { + binary[ind] = num % 2; + num /= 2; + ind--; + } + + if (number < 0) { + for (int i = 1; i < 32; i++) { + if (binary[i] == 1) { + binary[i] = 0; + } else { + binary[i] = 1; + } + } + binary[0] = 1; + + binary[31]++; + ind = 31; + while (binary[ind] == 2) { + binary[ind] = 0; + binary[ind - 1]++; + ind--; + } + } + return binary; +} + +int decimal(int num[]) +{ + int decimalNum = 0; + + if (num[0] == 0) { + for (int i = 1; i < 32; i++) { + int degree = pow(2, i - 1); + decimalNum += degree * num[31 - i + 1]; + } + return decimalNum; + } else { + for (int i = 1; i < 32; i++) { + if (num[i] == 1) { + num[i] = 0; + } else { + num[i] = 1; + } + } + num[0] = 1; + + num[31]++; + int ind = 31; + while (num[ind] == 2) { + num[ind] = 0; + num[ind - 1]++; + ind--; + } + + for (int i = 1; i < 32; i++) { + int degree = pow(2, i - 1); + decimalNum += degree * num[31 - i + 1]; + } + return -decimalNum; + } +} + +int* binSumm(int num1[], int num2[]) +{ + int* results = (int*)(malloc(32 * sizeof(int))); + int carry = 0; + + for (int i = 31; i > -1; i--) { + int sum = num1[i] + num2[i] + carry; + results[i] = sum % 2; + carry = sum / 2; + } + return results; +} + +int decSumm(int num1[], int num2[]) +{ + int* biSumm = binSumm(num1, num2); + int deSumm = decimal(biSumm); + return deSumm; +} diff --git a/n1/testsBinRep.c b/n1/testsBinRep.c new file mode 100644 index 0000000..f0adad8 --- /dev/null +++ b/n1/testsBinRep.c @@ -0,0 +1,62 @@ +#include "binRepresent" +#include +#include +#include +#include + +bool sravn(int* bin1, int* bin2) +{ + for (int i = 0; i < 32; i++) { + if (bin1[i] != bin2[i]) { + return false; + } + } + return true; +} + +bool run_tests() +{ + int s = 0; + + int a = 1; + int* b = bin(a); + int b2[32] = { 0 }; + b2[31] = 1; + if (sravn(b, b2)) { + s++; + } + printf("%d\n", s); + + int c = decimal(b); + if (c == 1) { + s++; + } + printf("%d\n", s); + + int* d = bin(-a); + int* e = binSumm(d, b); + int e2[32] = { 0 }; + if (sravn(e, e2)) { + s++; + } + printf("%d\n", s); + + int f = decSumm(d, b); + if (f == 0) { + s++; + } + printf("%d\n", s); + + return s == 4; +} + +int main(int argc, char* argv[]) +{ + if (argc == 2 && strcmp(argv[1], "--test") == 0) { + if (run_tests()) { + return 0; + } else { + return 1; + } + } +} \ No newline at end of file