by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 2.7, Creation date: 2015-10-04, Last change: 2025-09-14
b=isint32(a)
a: | number |
b: | true if isequal((rem(a,1),0) |
This function, isint32, determines if a given number a is an integer without a fractional part, specifically within the limits of an int32 data type.
true if the number a has no fractional part, i.e., it is an integer. Otherwise, it returns false.The function uses the mod function to determine if the number a has a fractional part. The expression mod(a, (1-1e-18)) calculates the remainder of a when divided by a value slightly less than 1. This is done to account for floating-point precision issues.
The result of mod(a, (1-1e-18)) is then compared to a small threshold value, 1e-9. If the remainder is less than 1e-9, it is considered negligible, and the function returns true, indicating that a is effectively an integer.
This method is faster than using isequal(rem(a,1),0) because it avoids the overhead of the rem function and directly checks for a negligible remainder.
The function is particularly useful in scenarios where the number of edges needs to be calculated, as indicated in the example usage: if ~isint32(nf); nf=nofrd(R,nf/2); end;