Skip to content

Commit 738678f

Browse files
committed
v1.0.3 clean up and doc improvements
1 parent c6476df commit 738678f

23 files changed

+2552
-147
lines changed

.github/workflows/ci.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, main, 2025_update ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
compiler: [gcc, clang]
16+
exclude:
17+
- os: macos-latest
18+
compiler: gcc # Use default clang on macOS
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Set up compiler
24+
run: |
25+
if [ "${{ matrix.compiler }}" = "gcc" ]; then
26+
echo "CC=gcc" >> $GITHUB_ENV
27+
echo "CXX=g++" >> $GITHUB_ENV
28+
else
29+
echo "CC=clang" >> $GITHUB_ENV
30+
echo "CXX=clang++" >> $GITHUB_ENV
31+
fi
32+
33+
- name: Build library
34+
run: make lib
35+
36+
- name: Build examples
37+
run: make examples
38+
39+
- name: Run tests
40+
run: make test
41+
42+
- name: Generate size report
43+
run: |
44+
echo "## Build Size Report (${{ matrix.os }} - ${{ matrix.compiler }})" >> $GITHUB_STEP_SUMMARY
45+
echo '```' >> $GITHUB_STEP_SUMMARY
46+
size build/*.o 2>/dev/null | head -5 >> $GITHUB_STEP_SUMMARY || echo "Size command not available" >> $GITHUB_STEP_SUMMARY
47+
echo '```' >> $GITHUB_STEP_SUMMARY
48+
49+
- name: Generate coverage report
50+
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc'
51+
run: |
52+
sudo apt-get update
53+
sudo apt-get install -y lcov
54+
make coverage
55+
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
56+
echo '```' >> $GITHUB_STEP_SUMMARY
57+
lcov --summary coverage/coverage.info >> $GITHUB_STEP_SUMMARY 2>&1
58+
echo '```' >> $GITHUB_STEP_SUMMARY
59+
60+
- name: Upload coverage to Codecov
61+
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc'
62+
uses: codecov/codecov-action@v3
63+
with:
64+
file: ./coverage/coverage.info
65+
flags: unittests
66+
name: codecov-umbrella
67+
fail_ci_if_error: false
68+
69+
cross-compile:
70+
runs-on: ubuntu-latest
71+
strategy:
72+
matrix:
73+
include:
74+
- target: arm-linux-gnueabihf
75+
arch: ARM
76+
- target: riscv64-linux-gnu
77+
arch: RISC-V
78+
79+
steps:
80+
- uses: actions/checkout@v3
81+
82+
- name: Install cross-compiler
83+
run: |
84+
sudo apt-get update
85+
sudo apt-get install -y gcc-${{ matrix.target }}
86+
87+
- name: Cross-compile
88+
run: |
89+
export CC=${{ matrix.target }}-gcc
90+
export CXX=${{ matrix.target }}-g++
91+
make lib
92+
93+
- name: Generate cross-compile size report
94+
run: |
95+
echo "## Cross-Compile Size Report (${{ matrix.arch }})" >> $GITHUB_STEP_SUMMARY
96+
echo '```' >> $GITHUB_STEP_SUMMARY
97+
${{ matrix.target }}-size build/*.o | head -5 >> $GITHUB_STEP_SUMMARY
98+
echo '```' >> $GITHUB_STEP_SUMMARY
99+
echo "" >> $GITHUB_STEP_SUMMARY
100+
echo "### Detailed sizes:" >> $GITHUB_STEP_SUMMARY
101+
echo '```' >> $GITHUB_STEP_SUMMARY
102+
ls -lh build/*.o >> $GITHUB_STEP_SUMMARY
103+
echo '```' >> $GITHUB_STEP_SUMMARY
104+
105+
test-32bit:
106+
runs-on: ubuntu-latest
107+
108+
steps:
109+
- uses: actions/checkout@v3
110+
111+
- name: Install 32-bit support
112+
run: |
113+
sudo apt-get update
114+
sudo apt-get install -y gcc-multilib g++-multilib
115+
116+
- name: Build and test 32-bit
117+
run: |
118+
export CFLAGS="-m32"
119+
export CXXFLAGS="-m32"
120+
make clean
121+
make test
122+
123+
- name: Generate 32-bit size report
124+
run: |
125+
echo "## 32-bit Build Size Report" >> $GITHUB_STEP_SUMMARY
126+
echo '```' >> $GITHUB_STEP_SUMMARY
127+
size build/*.o | head -5 >> $GITHUB_STEP_SUMMARY
128+
echo '```' >> $GITHUB_STEP_SUMMARY
129+
130+
overflow-tests:
131+
runs-on: ubuntu-latest
132+
133+
steps:
134+
- uses: actions/checkout@v3
135+
136+
- name: Build with sanitizers
137+
run: |
138+
export CFLAGS="-fsanitize=undefined -fsanitize=integer -fno-sanitize-recover=all"
139+
export CXXFLAGS="-fsanitize=undefined -fsanitize=integer -fno-sanitize-recover=all"
140+
make clean
141+
make test || true # Allow failure to see all issues
142+
143+
- name: Run overflow edge case tests
144+
run: |
145+
echo "Testing overflow and saturation behavior..."
146+
# This will be expanded when we enhance the test suite

.gitignore

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,74 @@
1-
#.gitignore for FR_Math
1+
# Build directories
2+
build/
3+
coverage/
4+
dist/
5+
lib/
26

3-
#editor auto-save intermediates
4-
*~
5-
6-
# Compiled Object files
7-
*.slo
8-
*.lo
7+
# Object files
98
*.o
9+
*.ko
1010
*.obj
11+
*.elf
1112

1213
# Precompiled Headers
1314
*.gch
1415
*.pch
1516

16-
# Compiled Dynamic libraries
17+
# Libraries
18+
*.lib
19+
*.a
20+
*.la
21+
*.lo
22+
23+
# Shared objects
24+
*.dll
1725
*.so
26+
*.so.*
1827
*.dylib
19-
*.dll
20-
21-
# Fortran module files
22-
*.mod
23-
*.smod
24-
25-
# Compiled Static libraries
26-
*.lai
27-
*.la
28-
*.a
29-
*.lib
3028

3129
# Executables
3230
*.exe
3331
*.out
3432
*.app
35-
*.
33+
*.i*86
34+
*.x86_64
35+
*.hex
36+
37+
# Debug files
38+
*.dSYM/
39+
*.su
40+
*.idb
41+
*.pdb
3642

37-
# profiling
43+
# Coverage files
3844
*.gcda
3945
*.gcno
46+
*.gcov
47+
*.info
48+
coverage.xml
49+
htmlcov/
50+
51+
# Editor files
52+
*~
53+
*.swp
54+
*.swo
55+
.vscode/
56+
.idea/
57+
*.sublime-*
58+
59+
# OS files
60+
.DS_Store
61+
Thumbs.db
62+
63+
# Test outputs
64+
test_results/
65+
*.log
66+
67+
# Documentation build
68+
docs/_build/
69+
docs/html/
70+
71+
# Python cache (for tools)
72+
__pycache__/
73+
*.pyc
74+
*.pyo

CLAUDE.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Overview
6+
7+
FR_Math is a C language fixed-point math library for embedded systems. It provides integer-based math operations using fixed radix (binary point) representations, allowing fractional calculations without floating-point support.
8+
9+
## Building and Testing
10+
11+
### Build Commands
12+
13+
```bash
14+
# Build example program
15+
make FR_math_example1.exe
16+
17+
# Build and run tests with coverage
18+
make FR_math_test.exe && ./FR_math_test.exe
19+
20+
# Clean build artifacts
21+
make clean
22+
23+
# Clean all files including backups
24+
make cleanall
25+
```
26+
27+
### Compilation Flags
28+
The library uses `-Wall -Os -ftest-coverage -fprofile-arcs` for testing builds with coverage support.
29+
30+
## Architecture
31+
32+
### Core Components
33+
34+
1. **FR_defs.h** - Type definitions and platform abstractions
35+
- Defines `s8`, `s16`, `s32` for signed integers
36+
- Defines `u8`, `u16`, `u32` for unsigned integers
37+
38+
2. **FR_math.h/c** - Core fixed-radix math operations
39+
- Macros for basic operations (add, multiply, conversions)
40+
- Trigonometric functions (sin, cos, tan)
41+
- Logarithmic and exponential functions
42+
- Fixed-point to integer conversions
43+
44+
3. **FR_math_2D.h/cpp** - 2D coordinate transformations
45+
- Matrix operations for graphics transforms
46+
- Scale, rotate, translate operations
47+
- World-to-camera transformations
48+
49+
### Key Conventions
50+
51+
- **Radix Notation**: Numbers use "sM.N" notation where:
52+
- `s` = signed, `u` = unsigned
53+
- `M` = integer bits
54+
- `N` = fractional bits
55+
- Example: `s11.4` = signed, 11 integer bits, 4 fractional bits
56+
57+
- **Macro Naming**: All macros are UPPERCASE with `FR_` prefix
58+
- Example: `FR_ADD()`, `FR_MUL()`, `FR_ABS()`
59+
60+
- **Type Safety**: Use typedef'd types (`s8`, `s16`, `s32`, etc.) not raw C types
61+
62+
### Fixed-Point Operations
63+
64+
- **Alignment**: Addition/subtraction require aligned radix points
65+
- **Multiplication**: Results in M+N bit precision (may need truncation)
66+
- **Saturation**: Library supports saturating math to prevent overflow
67+
- **Conversions**: Use `FR_CHRDX()` to change between radix representations
68+
69+
## Dependencies
70+
71+
The library has NO external dependencies - it compiles standalone on any C compiler without floating-point libraries.
72+
73+
## Testing
74+
75+
- Test file: `fr_math_test.c`
76+
- Uses Travis CI for continuous integration (`.travis.yml`)
77+
- Coverage reporting via lcov and coveralls

0 commit comments

Comments
 (0)