From 2f7a6d3c24fae6f548eab4cac7c4b581ec39d156 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 21 Nov 2025 22:48:31 +0300 Subject: [PATCH 1/7] Add .clang-format --- .clang-format | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f00c630 --- /dev/null +++ b/.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 +... From ef62ccc022382b9c8925f40484deca6044df7ebd Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 21 Nov 2025 22:57:44 +0300 Subject: [PATCH 2/7] Add build-and-lint.yml --- .github/workflows/build-and-lint.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/build-and-lint.yml diff --git a/.github/workflows/build-and-lint.yml b/.github/workflows/build-and-lint.yml new file mode 100644 index 0000000..a2c12fd --- /dev/null +++ b/.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 From 55d7b51f050bd3d9f0d2a17aadd36cd962fedf27 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 21 Nov 2025 22:58:44 +0300 Subject: [PATCH 3/7] Add dependabot.yml --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..58865cf --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: "weekly" From 6f45676ee7805adb77b6674e7a551fb1b2c66051 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 21 Nov 2025 23:01:05 +0300 Subject: [PATCH 4/7] Rename job in build-and-lint.yml --- .github/workflows/build-and-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-lint.yml b/.github/workflows/build-and-lint.yml index a2c12fd..de3a875 100644 --- a/.github/workflows/build-and-lint.yml +++ b/.github/workflows/build-and-lint.yml @@ -5,7 +5,7 @@ on: - pull_request jobs: - build-and-lint: + check-format: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 From bcd128194d093cd0965e9e5ce5727f5db1d3a2c8 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Sun, 30 Nov 2025 13:01:56 +0300 Subject: [PATCH 5/7] Add double under microscope --- .../double_under_microscope.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/double_under_microscope/double_under_microscope.c diff --git a/src/double_under_microscope/double_under_microscope.c b/src/double_under_microscope/double_under_microscope.c new file mode 100644 index 0000000..619172a --- /dev/null +++ b/src/double_under_microscope/double_under_microscope.c @@ -0,0 +1,32 @@ +#include + +typedef struct BitField { + unsigned long mantissa : 52; + unsigned int exp : 11; + unsigned int sign : 1; +} BitField; + +typedef union Number { + double number; + BitField bitField; +} Number; + +int main() +{ + Number number; + printf("Enter a number: "); + scanf("%lf", &number.number); + + char sign = number.bitField.sign ? '-' : '+'; + // Считаем экспоненту. + int exponent = number.bitField.exp - 1023; + // Считаем мантиссу. + double mantissa = number.bitField.mantissa; + unsigned long two_in_52_pow = 1; + two_in_52_pow = two_in_52_pow << 52; + double mantissaNormalized = 1 + mantissa / two_in_52_pow; + + printf("Result: %c%.52f*2^%d\n", sign, mantissaNormalized, exponent); + + return 0; +} From 83174ad8b36fed00e064e3e35f3aa71858ff8b63 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Sun, 30 Nov 2025 13:02:36 +0300 Subject: [PATCH 6/7] Add CMakeLists.txt for build double under microscope --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..40b763d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.25) +project(double_under_microscope C) + +add_executable(double_under_microscope src/double_under_microscope/double_under_microscope.c) +target_compile_options(double_under_microscope PRIVATE -Wall -Wextra -pedantic) From 78d73bcc692e39afc8b16517c927b72a00f76508 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Sun, 30 Nov 2025 13:03:08 +0300 Subject: [PATCH 7/7] Add build directory to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b48d248..b1e499b 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,7 @@ Module.symvers Mkfile.old dkms.conf +# CMake +build + # End of https://www.toptal.com/developers/gitignore/api/c