This repo contains a small didactic R/C++ package for exploring fast reciprocal square root routines (Quake-style magic constants, Newton refinements, bin searches, and related diagnostics). Use this file as your single source of truth when touching any part of the project.
- Keep the package reproducible and well-documented; every behavioural change should be explained via roxygen comments in the relevant
.Rfile. - Preserve the teaching value: prefer clear names, short functions, and comments that connect R interfaces to their C++ helpers.
- Avoid surprise state: seed the RNG in examples/tests and note parameters (
magic,NRmax,tol,threads).
R/: user-facing R functions and roxygen docs (edit here, not inman/).src/: C++ implementations called via.Call; each entry point wraps work inRcpp::RNGScopeand may useRcppParallel.man/: generated.Rdfiles. Never edit by hand.tests/:testthatcoverage for exported functions and bridge behaviour.README.md: runnable examples and orientation.
- Fast feedback:
R -q -e "pkgload::load_all('.'); testthat::test_dir('tests/testthat', reporter='summary')". - Full check (only when needed):
R CMD build .thenR CMD check frsrr_<version>.tar.gz. - Keep temporary build artefacts (
frsrr.Rcheck/, tarballs) out of git.
- R code: validate inputs early, keep vectorised operations where practical, and align argument names/behaviour across functions (
frsr,frsr_sample,frsr_bin,frsr_phase,frsr_NR). - C++ code: prefer modern C++20, keep functions small, and leave brief comments near tricky bit manipulations or Newton steps. Avoid try/catch around imports.
- Threading: respect user-provided
threadsoroptions(frsrr.threads); avoid oversubscribing shared hardware. - Performance notes belong in comments or docstrings, not hidden magic numbers.
- Update roxygen comments alongside code changes; regenerate docs with
devtools::document(roclets = c('rd','collate','namespace'))when necessary. - Examples should run quickly; use small inputs but include seeds so outputs are reproducible.
- Understand the data contract for the function you are editing (inputs, outputs, and any diagnostic columns).
- Add or adjust tests that cover new behaviour or bug fixes.
- Run the relevant tests/commands above and note them in your summary.
- Keep commits focused and messages descriptive.
- Core entry points:
R/frsr.R,R/sample.R,R/bin.R,R/phase.R,R/nr.Rwith matching C++ insrc/. - Thread config helper:
R/threads.R.
Follow this guide to keep the project coherent and approachable for anyone exploring fast reciprocal square root techniques.