© 2025 Alexander Hajnal v1.0.0
A set of number-related functions for OpenSCAD that closely follow those in the C standard library and Perl.
Note: This is a preview release of this library file. Many additional functions are planned to be added in the near future.
In future this library will contain various functions, primarily from C, that can be used to parse strings into numeric values.
The semantics are usually similar but not identical to their C and Perl equivalents so cf. the syntax descriptions below. The first character of all strings is at index 0 a.k.a. offset 0 (e.g. in the string ABC the letter A is at index 0). As a general rule, all C pointers are changed to string indices and all C NULL values are changed to undef.
To include in your code by placing this file in the same directory as your OpenSCAD script and including the following in your script:
use <c_numeric.scad>;
A stand-alone demo/test script can be found in c_numeric-test.scad.
Some functions are for internal use only and they should never be called from user code. These function are indicated by the name ending in an underscore followed by uppercase letters or underscores, optionally followed by additional alphanumeric characters. Some examples:
function something_PRIVATE_FUNCTION(args) = …
function something_PRIVATE_variant(args) = …
Please submit any bug reports or feature requests via GitHub.
-
strtol(string, base=0)Returns the value ofstringinterpreted as a number with the givenbase.Base can be 0 or any value between 2 and 36, inclusive. If base is 0 or no base is specified then the function will attempt to deduce the base (octal or hex), defaulting to decimal if none could be determined.
Note that the C function's range checking and end pointer are not currently supported.
See
strtol(3)andstrtol(…)below for details.
Major versions indicate a non-backwards-compatible change to the API.
Minor versions indicate substantial new features or bug fixes.
Subminor versions indicate changes that don't [yet] warrant incrementing the minor version number.
A suffix may be added when the changes are so inconsequential that incrementing the version number isn't warranted. This may include things like tweaks to comment formatting, indents, and the like. It does not include any changes to the code's logic or syntax.
-
c_numeric_version()Returns the c_numeric library version as an OpenSCAD list:[ Major, Minor, Subminor, Suffix ](e.g.
[ 1, 0, 2, "bis" ]) -
c_numeric_version_string()Returns the c_numeric library version as an OpenSCAD list:"Major.Minor.SubminorSuffix"(e.g.
"1.0.2bis") -
c_numeric_require( major, minor, subminor )Require at least the specified version of c_numeric. Throws a fatal error if thec_numericlibrary version is less than the one specified. All arguments are optional. Note that the suffix is ignored.Throws a fatal error if the c_numeric library version is less than the one specified.
This is a module and returns no value.
-
c_numeric_require_exact(major,minor,subminor)Require a specific version of c_numericThrows a fatal error if the c_numeric library version does not equal the one specified. All arguments are optional. Note that the suffix is ignored.
This is a module and returns no value.
Note: To require any version of c_numeric with a specific major (i.e. with a compatible API) but with at least a given revision (minor or minor.subminor) use e.g.:
c_numeric_require_exact(major=1); // Any 1.x.y version
c_numeric_require(major=1, minor=2); // Version 1.2.y or later
-
c_numeric_version_major()Returns thec_numericlibrary major version number as an integer. -
c_numeric_version_minor()Returns thec_numericlibrary minor version number as an integer. -
c_numeric_version_subminor()Returns thec_numericlibrary subminor version number as an integer. -
c_numeric_version_suffix()Returns thec_numericlibrary version suffix as a string.
1.0.0 [2025-11-24] Initial public release
- Initial version