galaxon/core

Core PHP utilities for floats, integers, arrays, types, and string conversion with IEEE-754 support.

Maintainers

Package info

github.com/mossy2100/Galaxon-PHP-Core

pkg:composer/galaxon/core

Statistics

Installs: 17

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

v1.5.1 2026-04-01 20:54 UTC

This package is auto-updated.

Last update: 2026-04-01 20:55:07 UTC


README

A general purpose library containing core utility classes and methods for use by other Galaxon PHP packages.

License | Changelog | Documentation

PHP 8.4

Description

This package provides a comprehensive set of utility classes for working with various PHP types and common operations. All utility classes are final with static methods and cannot be instantiated.

Development and Quality Assurance / AI Disclosure

Claude Chat and Claude Code were used in the development of this package. The core classes were designed, coded, and commented primarily by the author, with Claude providing substantial assistance with code review, suggesting improvements, debugging, and generating tests and documentation. All code was thoroughly reviewed by the author, and validated using industry-standard tools including PHP_Codesniffer, PHPStan (to level 9), and PHPUnit to ensure full compliance with PSR-12 coding standards and comprehensive unit testing with 100% code coverage. This collaborative approach resulted in a high-quality, thoroughly-tested, and well-documented package delivered in significantly less time than traditional development methods.

Code Coverage

Requirements

  • PHP ^8.4

Installation

composer require galaxon/core

Classes

Numbers

General number-related utility methods including sign operations.

Floats

Float-specific utilities for handling IEEE-754 special values (-0.0, ±INF, NAN), approximate comparison, float space navigation (next/previous), random generation, and IEEE-754 component assembly/disassembly.

Integers

Integer arithmetic operations with overflow checking (add, subtract, multiply, power), GCD calculation, and Unicode subscript/superscript conversion.

Arrays

Array utility methods including circular reference detection, value quoting, and first/last element extraction.

Types

Type checking and inspection utilities with methods for identifying numbers, unsigned integers, traits, and generating unique string keys.

Strings

String conversion and output utilities. Converts any value to a string, passing strings through as-is and using __toString() for Stringable objects.

Stringify

Advanced value-to-string conversion with pretty printing, supporting all PHP types with improved readability.

Functions

Functions

Convenience functions in the Galaxon\Core namespace, including println() for outputting strings and other values.

Traits

See Traits Overview for how these traits work together.

Equatable

Base trait providing exact equality comparison. Defines an abstract equal() method for type-safe equality checks.

Comparable

Trait extending Equatable with ordering operations. Provides lessThan(), greaterThan(), etc. based on a single compare() method implementation.

ApproxEquatable

Trait extending Equatable with tolerance-based comparison. Adds approxEqual() for comparing floating-point values within configurable tolerances.

ApproxComparable

Trait combining Comparable and ApproxEquatable for complete comparison support. Adds approxCompare() for comparing floating-point values within configurable tolerances. Provides both exact and approximate equality with full ordering operations.

FloatAssertions

Trait for PHPUnit test cases providing assertApproxEqual() and assertApproxZero() methods. Produces informative failure messages showing expected/actual values and differences.

Exceptions

IncomparableTypesException

Exception thrown when attempting to compare values of incompatible types. Used by the Comparable and ApproxComparable traits. Automatically generates descriptive error messages.

FormatException

Exception thrown when a string has an invalid format for the desired operation. Extends DomainException. Useful for parse methods or constructors that accept string arguments.

Testing

The library includes comprehensive test coverage:

# Run all tests
vendor/bin/phpunit

# Run specific test class
vendor/bin/phpunit tests/NumbersTest.php

# Run with coverage (generates HTML report and clover.xml)
composer test

License

MIT License - see LICENSE for details

Support

For questions or suggestions, please open an issue.

Changelog

See CHANGELOG.md for version history and changes.