digit
digit

7R35C0/digit

MIT

The module contains functions that return the number of digits.

0 0 0 0
5
build.zig.zon  build.zig 
View on Github  
Updated: 12:24:16 PM Thu Nov 21 2024 Size: 24KB Created: 9:26:32 AM Mon Nov 18 2024
Dependencies:
No known dependencies
zig  fetch  --save  git+https://github.com/7R35C0/digit

README

The module contains functions that return the number of digits for a number, using various algorithms.

The code is based on following sources:

πŸ“Œ Implementation

All functions return the number of digits for a supported number, otherwise null.

Supported number types and ranges:

  • .ComptimeInt, .Int: βˆ“340282366920938463463374607431768211455
    • min(i129) = -340282366920938463463374607431768211456 it is accepted to cover the type
  • .ComptimeFloat, .Float:
    • comptime_float: βˆ“10384593717069655257060992658440193
    • f16: βˆ“2049
    • f32: βˆ“16777217
    • f64: βˆ“9007199254740993
    • f80: βˆ“36893488147419103234
    • f128: βˆ“10384593717069655257060992658440193

Note that for float numbers the type is important, for example:

  • 2050 as f16: returns null
  • 2050 as f32: returns 4, same as for any type greater than f16

Negative numbers are converted to their absolute value.

πŸ“Œ Final note

More information about digit counting algorithms can be found in the sources, links above. Also, some usage examples are in the demo files.