Results for “Numbers & numeric validation”
Small, practical examples. Search by task or narrow things down below.
Find the length of a calendar month
C#: DaysInMonth applies the Gregorian leap-year rules.
C#✓ Tested
Find the mean and median of readings
Python: Use statistics helpers to distinguish an arithmetic mean from a middle value.
Python✓ Tested
Format an integer into a caller-owned buffer
C++: to_chars avoids allocation and reports whether the buffer was large enough.
C++✓ Tested
Handle a failed string-to-integer conversion
C++: stoi throws invalid_argument when no conversion can be performed.
C++✓ Tested
Insert a value while preserving sorted order
Python: Use insort on an already sorted list; insertion still shifts later list elements.
Python✓ Tested
Inspect a substring without allocating a copy
C++: A string_view refers to existing storage and must not outlive that storage.
C++✓ Tested
Inspect a typed conversion error
Inspect a typed conversion error using a complete Go program with explicit sample inputs.
Go✓ Tested
Iterate over all regular-expression matches
C++: A regex iterator yields successive matches without manually updating an offset.
C++✓ Tested
Keep function-local assignments separate from caller state
PowerShell: Ordinary function assignments create local variables rather than replacing the caller’s variable.
PowerShell✓ Tested
Normalize canonically equivalent Unicode strings
C#: Normalize to NFC before an ordinal comparison of equivalent character sequences.
C#✓ Tested
Normalize equivalent Unicode strings
Python: Normalize to NFC before comparing canonically equivalent text.
Python✓ Tested
Parse a Boolean configuration value
Parse a Boolean configuration value using a complete Go program with explicit sample inputs.
Go✓ Tested