Skip to content

Harden numeric domain checks in math routines#2

Merged
amartinsmg merged 2 commits intomainfrom
codex/verify-algorithm-implementations-z1n0nh
Feb 11, 2026
Merged

Harden numeric domain checks in math routines#2
amartinsmg merged 2 commits intomainfrom
codex/verify-algorithm-implementations-z1n0nh

Conversation

@amartinsmg
Copy link
Owner

Motivation

  • Prevent undefined or invalid mathematical operations (division by zero, out-of-domain sqrt/acos/asin, invalid factorial arguments) by strengthening numeric preconditions across math helpers.
  • Ensure geometric helpers only accept valid polygon/line inputs to avoid degenerate cases and runtime errors.
  • Add boundary tests to cover edge cases (zero-selection arrangements, triangle polygon edge cases, near-degenerate law-of-cosines inputs and common logarithm checks).

Description

  • Added stricter input validation to logarithm so it now asserts num > 0, base > 0 and base != 1 in src/basic_operations.h.
  • Tightened trigonometry preconditions in src/trigonometry.h including sideRightTriangle requiring hypotenuse > sideA, sideTriangleLC requiring oppositeAngle in (0, π), angleTriangleLC enforcing triangle inequalities, and Law of Sines helpers validating angle ranges and asin argument bounds.
  • Enforced selected <= total for arrangement and arrangementlf in src/combinatorics.h to avoid negative factorial inputs.
  • Tightened probabilistic helpers in src/probability_distribution.h by requiring success <= trials for binominal and lambda >= 0 for poisson.
  • Strengthened geometric checks in src/geometry.h and src/area_shape.h to require nOfSides >= 3 for polygon helpers and to assert vertical-line handling in slopeOfLine.
  • Extended src/test/main.c with boundary tests: arrangement(7, 0), arrangementlf(7, 0), a near-degenerate sideTriangleLC(5,7,179°) check, logarithm(1000,10), and triangle polygon angle/diagonal checks.

Testing

  • Ran the full test suite with make test && ./debug/test and all tests passed after adjustments.
  • During debugging a single failing expectation for the near-degenerate Law of Cosines case was updated to match the correct rounded value and then re-run, after which ./debug/test completed successfully.
  • The automated test run used stdbuf -o0 ./debug/test for diagnostic output during investigation and verification.

Codex Task

@amartinsmg amartinsmg merged commit 890610a into main Feb 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant