# Numbers and constants¶

Swix defines several convince constants including π (or pi), φ (or phi), e, inf, as well as the smallest possible difference between a float or double, FLOAT_EPSILON and DOUBLE_EPSILON

It should be noted that this library defaults to the type double. While it does use the most memory, it’s the most precise. If the compiler ever complains about conversion or can’t find a function, try calling it with a double value.

I’ve extended the native types to include a dot syntax. That is, Int(3).double will return 3.0. These are included for Int, Double, CInt, and Float. For integrating with C, use Int(3).cint. For integrating with vDSP, use Int(1).stride or Int(N).length to get a vDSP_Stride or vDSP_Length respectively.

The library includes both ScalarArithmetic and swift-complex. This means that numbers have handy conversions and we can access complex numbers through 1.0+1.0.i respectively.

## Docs¶

numbers_swix.DOUBLE_EPSILON = 'smaller'[source]

The smallest possible difference between two doubles. See machine epsilon for more detail.

numbers_swix.FLOAT_EPSILON = 'small'[source]

The smallest possible difference between two floats. See machine epsilon for more detail.

numbers_swix.PYTHON_PATH = '~/anaconda/bin/ipython'[source]

Where is Python found? Used for imshow and savefig (testing on MacOSX only!). Assumes pylab is installed.

numbers_swix.S2_PREFIX = '\$$NSHomeDirectory())/Developer/swix/swix/swix/swix/'[source] The path that should point to the swix directory. The file imshow.py, numbers.swix would be found by appending to this path. numbers_swix.S2_TOLEANCE = 1e-09[source] The determines how close two numbers have to be equal. numbers_swix.binom(n, k)[source] Calculate the binomial coeffecint or n choose k. Parameters: n (Double) – n as in on the wiki page. k (Double) – k as in on the wiki page. numbers_swix.close(x, y)[source] See if two numbers are approximately equal. Parameters: x – Double. An input value. y – Double. Another value. Bool. True only if the two values are close numerically. Specifically, true only if \(|x-y|<\textrm{tol}$$.

>>> assert(close(0, 1e-10) == true)

numbers_swix.convience_elements()[source]

The built in numeric classes have convience elements.

• {Float|Double|Int|CInt}.int. Returns the integer value
• {Float|Double|Int|CInt}.float. The floating point value
• {Float|Double|Int|CInt}.double. The double value.
• String.floatValue, String.doubleValue. Converts the string to a numeric value by interpetting a NSString.
• String.nsstring. For interfacing with C.

• Int has an element cint, length, stride. Length and stride of for interacting with vDSP.
• Double has element cdouble,
• Float has element cfloat.
>>> assert(3.14.int == 3)
>>> assert("3.14".floatValue == 3.14)
>>> assert(vDSP_Stride(1) == 1.stride)
>>> assert(vDSP_Length(N) == N.length)

numbers_swix.deg2rad(x)[source]

Parameters: x (Double) – Angle in degrees. Double. Angle in radians.
numbers_swix.e = 2.718281828459045[source]

Euler’s number

numbers_swix.euler = 0.5772156649015329[source]

Euler’s constant

numbers_swix.factorial(n)[source]

Computes $$n \cdot (n-1) \ldots 2 \cdot 1 = n!$$

Parameters: n (Int) – The number to compute the factorial of. The factorial of n.
numbers_swix.inf = inf[source]

Infinity.

numbers_swix.isNumber(x)[source]

See if the input object is a number.

Parameters: x – AnyObject. Bool. True only if x is a number (a float, double, cint, int). Returns false for vector and matrix.
numbers_swix.operator_slash(lhs, rhs)[source]

Operator / converts integer divison to double division.

Parameters: lhs – Int. rhs – Int. Double = lhs / rhs
numbers_swix.phi = 1.618033988749895[source]

The golden ratio Also callable with φ

numbers_swix.pi = 3.141592653589793[source]

The classic circle constant, pi and $$\pi$$.

numbers_swix.rad2deg(x)[source]

numbers_swix.tau = 6.283185307179586[source]
The much more intuitive circle constant, tau and $$\tau$$.