conversion_functions¶
shortfx.fxNumeric.conversion_functions
¶
Numeric Conversions Module.
This module provides comprehensive functionality for numeric type conversions, including conversions between numeric types, string representations, different number bases, and specialized conversions for JavaScript interoperability.
Key Features
- Basic type conversions (int, float, bool, complex, string)
- Number base conversions (binary, hexadecimal, octal)
- Timestamp and datetime conversions
- Locale-aware string to number conversions
- JavaScript safe integer handling
- IEEE 754 and bytes conversions
Example
from shortfx.fxNumeric.conversion_functions import hex_to_int, float_to_int_truncated hex_to_int("0xFF") 255 float_to_int_truncated(3.9) 3
Functions¶
acres_to_hectares(acres: float) -> float
¶
Convert acres to hectares.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acres
|
float
|
Area in acres. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area in hectares. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If acres is not numeric. |
Usage Example
round(acres_to_hectares(1), 4) 0.4047
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
add_bool_to_int(boolean_value: bool, int_value: int) -> int
¶
Adds a boolean value to an integer.
In Python, True evaluates to 1 and False to 0 in numeric contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boolean_value
|
bool
|
The boolean value (True or False). |
required |
int_value
|
int
|
The integer to which the boolean will be added. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The result of the addition. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If 'boolean_value' is not a boolean or 'int_value' is not an integer. |
Example
add_bool_to_int(True, 2) 3 add_bool_to_int(False, 5) 5
Cost: O(1), boolean addition as integer.
Source code in shortfx/fxNumeric/conversion_functions.py
adiabatic_index_pressure(p1: Union[int, float], v1: Union[int, float], v2: Union[int, float], gamma: Union[int, float]) -> float
¶
Calculate final pressure in an adiabatic process.
P₂ = P₁ · (V₁/V₂)^γ
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Union[int, float]
|
Initial pressure in Pa. |
required |
v1
|
Union[int, float]
|
Initial volume. |
required |
v2
|
Union[int, float]
|
Final volume. |
required |
gamma
|
Union[int, float]
|
Adiabatic index (heat capacity ratio). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Final pressure in Pa. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If p1, v1, v2, or gamma not positive. |
Example
round(adiabatic_index_pressure(100000, 1.0, 0.5, 1.4), 2) 263901.58
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
adiabatic_temperature(t1: Union[int, float], v1: Union[int, float], v2: Union[int, float], gamma: Union[int, float] = 1.4) -> float
¶
Return the final temperature after adiabatic expansion/compression.
T₂ = T₁ · (V₁ / V₂)^(γ − 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t1
|
Union[int, float]
|
Initial temperature in K (must be > 0). |
required |
v1
|
Union[int, float]
|
Initial volume (must be > 0). |
required |
v2
|
Union[int, float]
|
Final volume (must be > 0). |
required |
gamma
|
Union[int, float]
|
Heat capacity ratio (default 1.4 for air, > 1). |
1.4
|
Returns:
| Type | Description |
|---|---|
float
|
Final temperature in kelvins. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0 or gamma ≤ 1. |
Example
round(adiabatic_temperature(300, 1, 0.5), 2) 395.85
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
angle_convert(value: Union[int, float], from_unit: str, to_unit: str) -> float
¶
Converts an angle between degrees, radians, and gradians.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[int, float]
|
The angle value. |
required |
from_unit
|
str
|
Source unit ("deg", "rad", or "grad"). |
required |
to_unit
|
str
|
Target unit ("deg", "rad", or "grad"). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The converted angle. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not numeric. |
ValueError
|
If units are invalid. |
Example
import math angle_convert(180, "deg", "rad") == math.pi True angle_convert(200, "grad", "deg") 180.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
angular_momentum(mass: Union[int, float], velocity: Union[int, float], radius: Union[int, float]) -> float
¶
Calculate angular momentum L = m·v·r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
velocity
|
Union[int, float]
|
Tangential velocity in m/s. |
required |
radius
|
Union[int, float]
|
Radius in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angular momentum in kg·m²/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass or radius is not positive. |
Example
angular_momentum(2, 3, 4) 24.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
antenna_gain_to_effective_area(gain_dbi: float, frequency_hz: float) -> float
¶
Convert antenna gain (dBi) to effective aperture area (m²).
A_e = (λ² × G) / (4π), where G is linear gain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gain_dbi
|
float
|
Antenna gain in dBi. |
required |
frequency_hz
|
float
|
Operating frequency in Hz. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Effective area in square meters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If frequency_hz is not positive. |
Example
round(antenna_gain_to_effective_area(10, 1e9), 4) 0.7162
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
atmospheres_to_pascals(atm: float) -> float
¶
Convert standard atmospheres to pascals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atm
|
float
|
Pressure in atmospheres. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure in pascals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If atm is not numeric. |
Usage Example
atmospheres_to_pascals(1) 101325.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bars_to_pascals(bars: float) -> float
¶
Convert bars to pascals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bars
|
float
|
Pressure in bars. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure in pascals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If bars is not numeric. |
Usage Example
bars_to_pascals(1) 100000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
base_to_decimal(text: str, radix: int) -> int
¶
Converts a string representation from the specified base to decimal.
Description
Parses a string as a number in the given radix (2–36) and returns the equivalent decimal integer. Equivalent to Excel DECIMAL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string representing the number in the given base. |
required |
radix
|
int
|
The base of the input number (2 to 36). |
required |
Returns:
| Type | Description |
|---|---|
int
|
The decimal integer value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string or radix is not an integer. |
ValueError
|
If the text contains invalid digits for the given base, or the radix is outside 2–36. |
Example
base_to_decimal('FF', 16) 255 base_to_decimal('1010', 2) 10 base_to_decimal('144', 8) 100
Complexity: O(n) where n is the length of the text.
Source code in shortfx/fxNumeric/conversion_functions.py
bending_moment(force: float, distance: float) -> float
¶
Calculates the bending moment M = F × d.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
float
|
Applied force in Newtons. |
required |
distance
|
float
|
Perpendicular distance from pivot in metres. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Bending moment in N·m. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
Example
bending_moment(100, 2.5) 250.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bernoulli_velocity(pressure_diff: Union[int, float], fluid_density: Union[int, float]) -> float
¶
Calculate flow velocity from pressure difference (Bernoulli's eq.).
v = √(2·ΔP / ρ)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pressure_diff
|
Union[int, float]
|
Pressure difference in Pa. |
required |
fluid_density
|
Union[int, float]
|
Fluid density in kg/m³. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Flow velocity in m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If pressure_diff is negative or density not positive. |
Example
round(bernoulli_velocity(500, 1.225), 4) 28.5714
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bin_to_hex(binary: str) -> str
¶
Converts a binary string to hexadecimal.
Description
Parses a binary string and returns its hexadecimal representation. Equivalent to Excel BIN2HEX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary
|
str
|
A string of 0s and 1s (optional '0b' prefix). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Uppercase hexadecimal string without prefix. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not a string. |
ValueError
|
If the string contains invalid binary digits. |
Example
bin_to_hex('11111111') 'FF' bin_to_hex('1010') 'A'
Complexity: O(n)
Source code in shortfx/fxNumeric/conversion_functions.py
bin_to_int(bin_string: str) -> int
¶
Converts a binary string to an integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_string
|
str
|
The binary string (may have '0b' prefix). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The decimal integer. |
Example
bin_to_int("0b1010") 10 bin_to_int("111") 7
Cost: O(n), where n is the length of the binary string.
Source code in shortfx/fxNumeric/conversion_functions.py
bin_to_oct(binary: str) -> str
¶
Converts a binary string to octal.
Description
Parses a binary string and returns its octal representation. Equivalent to Excel BIN2OCT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary
|
str
|
A string of 0s and 1s (optional '0b' prefix). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Octal string without prefix. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not a string. |
ValueError
|
If the string contains invalid binary digits. |
Example
bin_to_oct('11111111') '377' bin_to_oct('1000') '10'
Complexity: O(n)
Source code in shortfx/fxNumeric/conversion_functions.py
biot_number(h: Union[int, float], l_c: Union[int, float], k: Union[int, float]) -> float
¶
Return the Biot number for conductive heat transfer.
Bi = h · L_c / k. Used to determine whether a lumped-system analysis is valid (Bi < 0.1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Union[int, float]
|
Convective heat transfer coefficient W/(m²·K) (> 0). |
required |
l_c
|
Union[int, float]
|
Characteristic length in metres (> 0). |
required |
k
|
Union[int, float]
|
Thermal conductivity of the solid W/(m·K) (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Biot number (dimensionless). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0. |
Example
biot_number(50, 0.01, 200) 0.0025
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bmi(weight_kg: Union[int, float], height_m: Union[int, float]) -> float
¶
Calculate Body Mass Index (BMI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight_kg
|
Union[int, float]
|
Weight in kilograms. |
required |
height_m
|
Union[int, float]
|
Height in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
BMI value as a float. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If weight_kg or height_m is not positive. |
Example
round(bmi(70, 1.75), 2) 22.86
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bool_to_float(value: bool) -> float
¶
Converts a boolean value to a floating-point number. True converts to 1.0; False converts to 0.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
The boolean value to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The resulting float number. |
Example
bool_to_float(True) 1.0 bool_to_float(False) 0.0
Cost: O(1), direct boolean to float conversion.
Source code in shortfx/fxNumeric/conversion_functions.py
bool_to_int(value: bool) -> int
¶
Converts a boolean value to an integer. True converts to 1; False converts to 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
The boolean value to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The resulting integer. |
Example
bool_to_int(True) 1 bool_to_int(False) 0
Cost: O(1), direct boolean to integer conversion.
Source code in shortfx/fxNumeric/conversion_functions.py
boyle_law_volume(p1: Union[int, float], v1: Union[int, float], p2: Union[int, float]) -> float
¶
Return the new volume using Boyle's law.
At constant temperature: P₁ · V₁ = P₂ · V₂ ⟹ V₂ = P₁ · V₁ / P₂.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Union[int, float]
|
Initial pressure (must be > 0). |
required |
v1
|
Union[int, float]
|
Initial volume (must be > 0). |
required |
p2
|
Union[int, float]
|
Final pressure (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Final volume as a float. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0. |
Example
boyle_law_volume(2, 10, 4) 5.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
btu_to_joules(btu: float) -> float
¶
Convert British thermal units to joules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
btu
|
float
|
Energy in BTU. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If btu is not numeric. |
Usage Example
round(btu_to_joules(1), 2) 1055.06
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bulk_modulus_pressure(bulk_modulus: Union[int, float], volume_change: Union[int, float], original_volume: Union[int, float]) -> float
¶
Calculate pressure change from bulk modulus.
ΔP = -K · (ΔV / V₀)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bulk_modulus
|
Union[int, float]
|
Bulk modulus in pascals. |
required |
volume_change
|
Union[int, float]
|
Change in volume (negative for compression). |
required |
original_volume
|
Union[int, float]
|
Original volume. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure change in pascals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If bulk_modulus or original_volume is not positive. |
Example
bulk_modulus_pressure(2.2e9, -0.001, 1.0) 2200000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
buoyancy_force(fluid_density: Union[int, float], displaced_volume: Union[int, float], gravity: float = 9.80665) -> float
¶
Return the buoyancy force on an immersed object (Archimedes).
F_b = ρ · V · g.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fluid_density
|
Union[int, float]
|
Density of the fluid in kg/m³ (must be > 0). |
required |
displaced_volume
|
Union[int, float]
|
Displaced volume in m³ (must be > 0). |
required |
gravity
|
float
|
Gravitational acceleration in m/s² (default 9.80665). |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Buoyancy force in newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0. |
Example
round(buoyancy_force(1000, 0.01), 4) 98.0665
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
buoyant_force(fluid_density: Union[int, float], displaced_volume: Union[int, float], gravity: Union[int, float] = 9.80665) -> float
¶
Calculate buoyant force using Archimedes' principle: F = ρ * V * g.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fluid_density
|
Union[int, float]
|
Density of the fluid in kg/m³. |
required |
displaced_volume
|
Union[int, float]
|
Volume of fluid displaced in m³. |
required |
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s² (default 9.80665). |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Buoyant force in Newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If fluid_density or displaced_volume is not positive. |
Example
round(buoyant_force(1000, 0.01), 2) 98.07
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bytes_to_human_readable(size_bytes: int) -> str
¶
Convert bytes to human-readable string (B, KB, MB, GB, TB).
Uses binary prefixes (1 KB = 1024 B).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size_bytes
|
int
|
Size in bytes (≥ 0). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string like |
Raises:
| Type | Description |
|---|---|
TypeError
|
If size_bytes is not an integer. |
ValueError
|
If size_bytes is negative. |
Usage Example
bytes_to_human_readable(1572864) '1.50 MB'
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
bytes_to_int(byte_sequence: bytes, byteorder: str = 'big') -> int
¶
Converts a byte sequence to an integer.
Description
Useful for decoding data received through a binary protocol or reading numeric values from binary files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
byte_sequence
|
bytes
|
The byte sequence to convert. |
required |
byteorder
|
str
|
Byte order ('big' or 'little'). Default is 'big'. |
'big'
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The integer represented by the byte sequence. |
Usage Example
bytes_to_int(b' {', 'big') 123 bytes_to_int(b' ', 'little') 256
Cost: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
calories_to_joules(cal: float) -> float
¶
Convert thermochemical calories to joules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cal
|
float
|
Energy in calories. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If cal is not numeric. |
Usage Example
calories_to_joules(1000) 4184.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
candela_to_lumens(cd: float, solid_angle_sr: float = 12.566370614359172) -> float
¶
Convert luminous intensity (candela) to luminous flux (lumens).
Lumens = candela × solid angle (steradians). Default solid angle is 4π sr (full sphere).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cd
|
float
|
Luminous intensity in candela. |
required |
solid_angle_sr
|
float
|
Solid angle in steradians (default 4π). |
12.566370614359172
|
Returns:
| Type | Description |
|---|---|
float
|
Luminous flux in lumens. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If cd or solid_angle_sr is not numeric. |
Usage Example
round(candela_to_lumens(1), 2) 12.57
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
capacitance_parallel_plate(area: Union[int, float], distance: Union[int, float], epsilon_r: Union[int, float] = 1.0) -> float
¶
Calculate parallel plate capacitance C = ε₀·εᵣ·A/d.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Union[int, float]
|
Plate area in m². |
required |
distance
|
Union[int, float]
|
Plate separation in meters. |
required |
epsilon_r
|
Union[int, float]
|
Relative permittivity (default 1.0 for vacuum). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Capacitance in farads. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If area, distance, or epsilon_r not positive. |
Example
round(capacitance_parallel_plate(0.01, 0.001), 14) 8.854187817e-11
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
capacitive_reactance(frequency: Union[int, float], capacitance: Union[int, float]) -> float
¶
Return the capacitive reactance of a capacitor.
X_C = 1 / (2π · f · C).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
Union[int, float]
|
Frequency in hertz (must be > 0). |
required |
capacitance
|
Union[int, float]
|
Capacitance in farads (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Capacitive reactance in ohms. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If frequency or capacitance ≤ 0. |
Example
round(capacitive_reactance(60, 10e-6), 2) 265.26
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
capacitor_energy(capacitance: Union[int, float], voltage: Union[int, float]) -> float
¶
Calculate energy stored in a capacitor: E = 0.5 * C * V².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capacitance
|
Union[int, float]
|
Capacitance in Farads. |
required |
voltage
|
Union[int, float]
|
Voltage across the capacitor in Volts. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If capacitance is not positive. |
Example
capacitor_energy(0.001, 10) 0.05
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
centripetal_acceleration(velocity: Union[int, float], radius: Union[int, float]) -> float
¶
Calculate centripetal acceleration a = v² / r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[int, float]
|
Tangential velocity (m/s). |
required |
radius
|
Union[int, float]
|
Radius of circular path (m). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Centripetal acceleration in m/s². |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If radius is not positive. |
Example
centripetal_acceleration(10, 5) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
centripetal_force(mass: Union[int, float], velocity: Union[int, float], radius: Union[int, float]) -> float
¶
Calculate centripetal force F = m·v²/r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
velocity
|
Union[int, float]
|
Tangential velocity in m/s. |
required |
radius
|
Union[int, float]
|
Radius of circular path in m. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Centripetal force in newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass or radius is not positive. |
Example
centripetal_force(2, 10, 5) 40.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
charles_law_volume(v1: Union[int, float], t1: Union[int, float], t2: Union[int, float]) -> float
¶
Return the new volume using Charles's law.
At constant pressure: V₁ / T₁ = V₂ / T₂ ⟹ V₂ = V₁ · T₂ / T₁. Temperatures must be in kelvins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v1
|
Union[int, float]
|
Initial volume (must be > 0). |
required |
t1
|
Union[int, float]
|
Initial temperature in K (must be > 0). |
required |
t2
|
Union[int, float]
|
Final temperature in K (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Final volume as a float. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0. |
Example
charles_law_volume(10, 300, 600) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
cmyk_to_rgb(c: float, m: float, y: float, k: float) -> tuple
¶
Convert CMYK colour to RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
float
|
Cyan in [0, 1]. |
required |
m
|
float
|
Magenta in [0, 1]. |
required |
y
|
float
|
Yellow in [0, 1]. |
required |
k
|
float
|
Key/Black in [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple (r, g, b) with values in 0–255. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any channel is outside [0, 1]. |
Usage Example
cmyk_to_rgb(0.0, 1.0, 1.0, 0.0) (255, 0, 0)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
color_contrast_ratio(r1: int, g1: int, b1: int, r2: int, g2: int, b2: int) -> float
¶
WCAG 2.1 contrast ratio between two sRGB colours.
Description
Ratio = (L_lighter + 0.05) / (L_darker + 0.05), ranging from 1:1 (identical) to 21:1 (black vs white).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r1, g1, b1
|
First colour RGB channels (0–255 each). |
required | |
r2, g2, b2
|
Second colour RGB channels (0–255 each). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Contrast ratio as a float (>= 1.0). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not an integer. |
ValueError
|
If any channel is outside 0–255. |
Usage Example
color_contrast_ratio(0, 0, 0, 255, 255, 255) 21.0 color_contrast_ratio(255, 255, 255, 255, 255, 255) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
color_luminance(r: int, g: int, b: int) -> float
¶
Relative luminance of an sRGB colour per WCAG 2.1.
Description
L = 0.2126 R + 0.7152 G + 0.0722 B, where each channel is linearised from the sRGB gamma curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
int
|
Red channel (0–255). |
required |
g
|
int
|
Green channel (0–255). |
required |
b
|
int
|
Blue channel (0–255). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Relative luminance in [0, 1]. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not an integer. |
ValueError
|
If any channel is outside 0–255. |
Usage Example
round(color_luminance(255, 255, 255), 1) 1.0 round(color_luminance(0, 0, 0), 1) 0.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
color_temperature_to_rgb(kelvin: float) -> tuple[int, int, int]
¶
Convert a colour temperature (Kelvin) to an approximate RGB tuple.
Uses Tanner Helland's algorithm for the range 1000-40000 K.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kelvin
|
float
|
Colour temperature in Kelvin. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
Tuple |
Raises:
| Type | Description |
|---|---|
TypeError
|
If kelvin is not numeric. |
ValueError
|
If kelvin < 1000 or > 40000. |
Example
color_temperature_to_rgb(6500) (255, 254, 250)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
compton_wavelength_shift(angle: Union[int, float]) -> float
¶
Return the Compton wavelength shift for photon scattering.
Δλ = (h / (mₑ · c)) · (1 − cos θ), where θ is the scattering angle in radians.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
Union[int, float]
|
Scattering angle in radians. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Wavelength shift in metres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If angle is not numeric. |
Example
round(compton_wavelength_shift(math.pi), 15) 4.853e-12
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
convert_bytes_to(unit: str, value: Union[int, float, str]) -> float
¶
Converts a byte value to a specified target unit.
This function takes a byte value and converts it into a more readable unit (e.g., KB, MB, GB, KiB, MiB, GiB). It supports both SI (powers of 1000) and IEC (powers of 1024) units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str
|
The target unit for conversion (e.g., 'KB', 'MB', 'GB', 'TB', 'PB' for SI units, or 'KiB', 'MiB', 'GiB', 'TiB', 'PiB' for IEC units). |
required |
value
|
Union[int, float, str]
|
The byte value to convert. Can be an int, float, or a string that can be converted to a number. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The converted value as a float. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If 'value' cannot be converted to a numeric type. |
ValueError
|
If 'unit' is not a recognized conversion unit. |
Example
convert_bytes_to('KB', 1024) 1.024 convert_bytes_to('GiB', 1073741824) # 1 GiB 1.0 convert_bytes_to('GB', 1000000000) # 1 GB 1.0 convert_bytes_to('MB', 5242880) # 5 MiB 5.24288 convert_bytes_to('MiB', 5242880) # 5 MiB 5.0 convert_bytes_to('TB', 2_000_000_000_000) 2.0 convert_bytes_to('KiB', "2048") 2.0
Cost: O(1), conversión aritmética simple.
Source code in shortfx/fxNumeric/conversion_functions.py
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
convert_string_to_float_with_locale(number_string: str, target_locale: Optional[str] = None) -> float
¶
Converts a numeric string to a float, interpreting decimal and thousands separators according to a specific regional configuration (locale).
This function handles number input from different world regions where decimal and
thousands separators may vary (e.g., ',' vs '.'). It uses Python's locale module
to optionally set a specific target_locale for conversion. If target_locale is
provided, the function saves the current system locale, temporarily sets the new
locale, performs the conversion with locale.atof(), and then restores the
original locale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number_string
|
str
|
The string representing the number to convert. |
required |
target_locale
|
Optional[str]
|
The locale string to use for conversion (e.g., 'es_ES', 'de_DE', 'en_US'). If None, uses the current system locale. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The resulting floating-point number. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If 'number_string' is not a string. |
ValueError
|
If the string cannot be interpreted as a valid number within the specified locale, or if the locale is not valid. |
Example
Configuration for a locale using comma as decimal (e.g., Spanish from Spain)¶
convert_string_to_float_with_locale("1.234,56", 'es_ES') 1234.56 convert_string_to_float_with_locale("123,45", 'es_ES') 123.45
Configuration for a locale using dot as decimal (e.g., US English)¶
convert_string_to_float_with_locale("1,234.56", 'en_US') 1234.56 convert_string_to_float_with_locale("123.45", 'en_US') 123.45
Cost: O(n), where n is the length of the string. Includes locale operations.
Source code in shortfx/fxNumeric/conversion_functions.py
convert_units(number: Union[int, float], from_unit: str, to_unit: str) -> float
¶
Convert a value from one measurement unit to another.
Description
Supports 13 categories: length, mass, time, temperature, pressure, force, energy, power, volume, area, speed, angle, and information. Equivalent to Excel CONVERT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
Union[int, float]
|
Value to convert. |
required |
from_unit
|
str
|
Source unit abbreviation. |
required |
to_unit
|
str
|
Target unit abbreviation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Converted value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If number is not numeric. |
ValueError
|
If conversion is not supported. |
Example
convert_units(100, 'cm', 'm') 1.0 convert_units(1, 'kg', 'g') 1000.0 convert_units(0, 'C', 'F') 32.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 | |
coordinate_decimal_to_dms(decimal_degrees: Union[int, float], is_longitude: bool = False) -> tuple
¶
Converts decimal degrees to DMS (degrees, minutes, seconds, direction).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimal_degrees
|
Union[int, float]
|
The coordinate in decimal degrees. |
required |
is_longitude
|
bool
|
True for longitude (E/W), False for latitude (N/S). |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple (degrees, minutes, seconds, direction). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If decimal_degrees is not numeric. |
ValueError
|
If latitude not in [-90,90] or longitude not in [-180,180]. |
Example
coordinate_decimal_to_dms(40.4461) (40, 26, 45.96, 'N') coordinate_decimal_to_dms(-79.9822, is_longitude=True) (79, 58, 55.92, 'W')
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
coordinate_dms_to_decimal(degrees: int, minutes: int, seconds: Union[int, float], direction: str = 'N') -> float
¶
Converts geographic coordinates from DMS to decimal degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
degrees
|
int
|
Degree component (0–180 for lon, 0–90 for lat). |
required |
minutes
|
int
|
Minutes component (0–59). |
required |
seconds
|
Union[int, float]
|
Seconds component (0–59.999…). |
required |
direction
|
str
|
Cardinal direction ("N", "S", "E", "W"). |
'N'
|
Returns:
| Type | Description |
|---|---|
float
|
Decimal degrees (negative for S and W). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If degrees/minutes are not ints or seconds not numeric. |
ValueError
|
If components are out of range or direction invalid. |
Example
round(coordinate_dms_to_decimal(40, 26, 46, "N"), 4) 40.4461 round(coordinate_dms_to_decimal(79, 58, 56, "W"), 4) -79.9822
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
coulomb_force(charge1: Union[int, float], charge2: Union[int, float], distance: Union[int, float]) -> float
¶
Calculate electrostatic force: F = k * |q₁·q₂| / r².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge1
|
Union[int, float]
|
First charge in Coulombs. |
required |
charge2
|
Union[int, float]
|
Second charge in Coulombs. |
required |
distance
|
Union[int, float]
|
Distance between charges in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Force magnitude in Newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If distance is not positive. |
Example
round(coulomb_force(1e-6, 2e-6, 0.05), 4) 7.1928
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
coulombs_force(q1: Union[int, float], q2: Union[int, float], distance: Union[int, float]) -> float
¶
Return the electrostatic force between two point charges.
F = k · |q₁ · q₂| / r², where k ≈ 8.9876 × 10⁹ N·m²/C².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q1
|
Union[int, float]
|
First charge in coulombs. |
required |
q2
|
Union[int, float]
|
Second charge in coulombs. |
required |
distance
|
Union[int, float]
|
Distance between charges in metres (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Electrostatic force magnitude in newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If distance is zero or negative. |
Example
round(coulombs_force(1e-6, 2e-6, 0.05), 4) 7.19
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
coulombs_law(q1: Union[int, float], q2: Union[int, float], distance: Union[int, float]) -> float
¶
Computes electrostatic force via Coulomb's law.
F = k × |q1 × q2| / d².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q1
|
Union[int, float]
|
Charge 1 in coulombs. |
required |
q2
|
Union[int, float]
|
Charge 2 in coulombs. |
required |
distance
|
Union[int, float]
|
Distance between charges in metres (must be positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Force magnitude in newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If distance is zero or negative. |
Example
round(coulombs_law(1e-6, 2e-6, 0.05), 4) 7.19
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
cubic_meters_per_second_to_liters_per_minute(cms: float) -> float
¶
Convert cubic meters per second to liters per minute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cms
|
float
|
Flow rate in m³/s. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Flow rate in liters per minute. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If cms is not numeric. |
Usage Example
cubic_meters_per_second_to_liters_per_minute(0.001) 60.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
current_divider(total_current: Union[int, float], r_branch: Union[int, float], r_other: Union[int, float]) -> float
¶
Return the branch current in a two-resistor current divider.
I_branch = I_total · R_other / (R_branch + R_other).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_current
|
Union[int, float]
|
Total current in amperes. |
required |
r_branch
|
Union[int, float]
|
Resistance of the branch of interest (> 0). |
required |
r_other
|
Union[int, float]
|
Resistance of the other branch (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Branch current in amperes. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If either resistance ≤ 0. |
Example
current_divider(10, 200, 100) 3.3333333333333335
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
db_to_power(decibels: Union[int, float]) -> float
¶
Convert decibels to a power ratio.
Description
Computes 10^(dB/10). Inverse of power_to_db.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decibels
|
Union[int, float]
|
Value in decibels. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Power ratio. |
Example
db_to_power(20) 100.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
db_to_voltage(decibels: Union[int, float]) -> float
¶
Convert decibels to a voltage/amplitude ratio.
Description
Computes 10^(dB/20). Inverse of voltage_to_db.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decibels
|
Union[int, float]
|
Value in decibels. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Voltage/amplitude ratio. |
Example
db_to_voltage(20) 10.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
de_broglie_wavelength(mass: Union[int, float], velocity: Union[int, float]) -> float
¶
Calculate de Broglie wavelength: λ = h / (m * v).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Particle mass in kg. |
required |
velocity
|
Union[int, float]
|
Particle velocity in m/s. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Wavelength in meters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass or velocity is not positive. |
Example
round(de_broglie_wavelength(9.109e-31, 1e6), 13) 7.274e-10
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
dec_to_oct(number: int) -> str
¶
Converts a decimal integer to octal.
Description
Returns the octal string representation of a non-negative integer. Equivalent to Excel DEC2OCT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
A non-negative integer. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Octal string without prefix. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not an integer. |
ValueError
|
If input is negative. |
Example
dec_to_oct(100) '144' dec_to_oct(8) '10'
Complexity: O(log n)
Source code in shortfx/fxNumeric/conversion_functions.py
decibel_add(db1: Union[int, float], db2: Union[int, float]) -> float
¶
Add two sound levels in decibels.
The result accounts for logarithmic combination of sound intensities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db1
|
Union[int, float]
|
First sound level in dB. |
required |
db2
|
Union[int, float]
|
Second sound level in dB. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Combined sound level in dB. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
Example
round(decibel_add(90, 90), 2) 93.01
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
decibel_sum(db_a: float, db_b: float) -> float
¶
Logarithmic addition of two sound levels in decibels.
dB_total = 10 · log₁₀(10^(dB_a/10) + 10^(dB_b/10))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_a
|
float
|
First sound level in dB. |
required |
db_b
|
float
|
Second sound level in dB. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Combined sound level in dB. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
Example
round(decibel_sum(90, 90), 2) 93.01
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
decimal_to_fraction(number: float, max_denominator: int = 1000) -> tuple
¶
Convert a decimal number to a fraction (numerator, denominator).
Uses the standard library fractions.Fraction for best rational
approximation up to max_denominator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
float
|
Decimal value to convert. |
required |
max_denominator
|
int
|
Maximum denominator allowed. Defaults to 1000. |
1000
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple (numerator, denominator). |
Example
decimal_to_fraction(0.75) (3, 4) decimal_to_fraction(3.14159, 100) (22, 7)
Complexity: O(log(max_denominator))
Source code in shortfx/fxNumeric/conversion_functions.py
degrees_to_gradians(deg: float) -> float
¶
Convert degrees to gradians (gon).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deg
|
float
|
Angle in degrees. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle in gradians. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If deg is not numeric. |
Usage Example
round(degrees_to_gradians(90), 4) 100.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
density_to_specific_gravity(density: float, reference: float = 997.0) -> float
¶
Convert density to specific gravity relative to a reference.
SG = ρ / ρ_ref. Default reference is water at 25 °C (997 kg/m³).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
density
|
float
|
Material density in kg/m³. |
required |
reference
|
float
|
Reference density in kg/m³ (default 997.0, > 0). |
997.0
|
Returns:
| Type | Description |
|---|---|
float
|
Specific gravity as a float. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If reference is not positive. |
Usage Example
round(density_to_specific_gravity(7874), 2) 7.9
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
dew_point(temperature_c: Union[int, float], relative_humidity: Union[int, float]) -> float
¶
Calculate dew point temperature using the Magnus formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature_c
|
Union[int, float]
|
Air temperature in Celsius. |
required |
relative_humidity
|
Union[int, float]
|
Relative humidity in percent (0-100). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Dew point in Celsius. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If humidity not in (0, 100]. |
Example
round(dew_point(25, 50), 2) 13.84
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
dft_magnitude(signal: list, k: int) -> float
¶
Computes the magnitude of the k-th DFT coefficient (standalone, no FFT).
|X[k]| = |Σ x[n] · e^(−j2πkn/N)|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
list
|
List of real-valued samples. |
required |
k
|
int
|
Frequency bin index (0 ≤ k < N). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Magnitude of the k-th DFT coefficient. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If signal is not a list or k is not an integer. |
ValueError
|
If signal is empty or k is out of range. |
Example
round(dft_magnitude([1, 0, -1, 0], 1), 6) 2.0
Complexity: O(N)
Source code in shortfx/fxNumeric/conversion_functions.py
dft_phase(signal: list, k: int) -> float
¶
Computes the phase (in radians) of the k-th DFT coefficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
list
|
List of real-valued samples. |
required |
k
|
int
|
Frequency bin index (0 ≤ k < N). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Phase in radians (−π to π). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If signal is not a list or k is not an integer. |
ValueError
|
If signal is empty or k is out of range. |
Example
round(dft_phase([1, 0, -1, 0], 1), 6) -1.570796
Complexity: O(N)
Source code in shortfx/fxNumeric/conversion_functions.py
doppler_freq(source_freq: Union[int, float], velocity: Union[int, float], wave_speed: Union[int, float] = 343.0) -> float
¶
Calculate observed frequency due to the Doppler effect.
Description
f_obs = f_src × (v_wave / (v_wave − v_source)). Positive velocity means the source approaches the observer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_freq
|
Union[int, float]
|
Emitted frequency in hertz (must be positive). |
required |
velocity
|
Union[int, float]
|
Source velocity in m/s (positive = approaching). |
required |
wave_speed
|
Union[int, float]
|
Medium wave speed in m/s (default: 343, sound in air). |
343.0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Observed frequency in hertz. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If source_freq or wave_speed is not positive, or velocity equals wave_speed. |
Example
round(doppler_freq(440, 30), 2) 482.17
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
doppler_frequency(source_freq: Union[int, float], wave_speed: Union[int, float], observer_speed: Union[int, float] = 0.0, source_speed: Union[int, float] = 0.0) -> float
¶
Return the observed frequency due to the Doppler effect.
f' = f_s · (v + v_o) / (v − v_s). Positive observer speed means moving toward the source; positive source speed means moving toward the observer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_freq
|
Union[int, float]
|
Frequency emitted by the source in Hz (> 0). |
required |
wave_speed
|
Union[int, float]
|
Speed of the wave in the medium in m/s (> 0). |
required |
observer_speed
|
Union[int, float]
|
Observer speed in m/s (toward source > 0). |
0.0
|
source_speed
|
Union[int, float]
|
Source speed in m/s (toward observer > 0). |
0.0
|
Returns:
| Type | Description |
|---|---|
float
|
Observed frequency in Hz. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If source_freq ≤ 0, wave_speed ≤ 0, or (wave_speed − source_speed) ≤ 0. |
Example
round(doppler_frequency(440, 343, 0, 30), 2) 482.17
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
doppler_shift(source_frequency: Union[int, float], relative_velocity: Union[int, float], wave_speed: Union[int, float] = 343.0) -> float
¶
Calculate observed frequency due to Doppler effect (source moving).
f_obs = f_src * v / (v + v_s) (positive v_s = moving away).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_frequency
|
Union[int, float]
|
Source frequency in Hz. |
required |
relative_velocity
|
Union[int, float]
|
Source velocity relative to observer (m/s, positive = receding). |
required |
wave_speed
|
Union[int, float]
|
Speed of the wave medium in m/s (default 343 for sound). |
343.0
|
Returns:
| Type | Description |
|---|---|
float
|
Observed frequency in Hz. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If source_frequency or wave_speed not positive, or denominator ≤ 0. |
Example
round(doppler_shift(440, 30), 2) 393.03
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
drag_force(drag_coefficient: Union[int, float], fluid_density: Union[int, float], velocity: Union[int, float], reference_area: Union[int, float]) -> float
¶
Calculate aerodynamic drag force: F_d = ½·C_d·ρ·v²·A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drag_coefficient
|
Union[int, float]
|
Dimensionless drag coefficient. |
required |
fluid_density
|
Union[int, float]
|
Fluid density in kg/m³. |
required |
velocity
|
Union[int, float]
|
Velocity in m/s. |
required |
reference_area
|
Union[int, float]
|
Reference area in m². |
required |
Returns:
| Type | Description |
|---|---|
float
|
Drag force in Newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If drag_coefficient, fluid_density, or reference_area is not positive. |
Example
drag_force(0.47, 1.225, 10, 0.01) 0.028787500000000002
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
drift_velocity(current: Union[int, float], n_density: Union[int, float], charge: Union[int, float], area: Union[int, float]) -> float
¶
Calculate charge carrier drift velocity v = I / (n·q·A).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current
|
Union[int, float]
|
Electric current in amperes. |
required |
n_density
|
Union[int, float]
|
Number density of carriers (m⁻³). |
required |
charge
|
Union[int, float]
|
Charge per carrier in coulombs. |
required |
area
|
Union[int, float]
|
Cross-sectional area in m². |
required |
Returns:
| Type | Description |
|---|---|
float
|
Drift velocity in m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If n_density, charge, or area not positive. |
Example
drift_velocity(10, 8.5e28, 1.6e-19, 1e-6) 0.0007352941176470589
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
elastic_modulus(stress: Union[int, float], strain: Union[int, float]) -> float
¶
Calculate Young's modulus (elastic modulus): E = stress / strain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stress
|
Union[int, float]
|
Applied stress in Pascals. |
required |
strain
|
Union[int, float]
|
Resulting strain (dimensionless, > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Young's modulus in Pascals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If strain is zero. |
Example
elastic_modulus(200e6, 0.001) 200000000000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
elastic_potential_energy(k: Union[int, float], x: Union[int, float]) -> float
¶
Calculate elastic potential energy U = ½·k·x².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
Union[int, float]
|
Spring constant in N/m. |
required |
x
|
Union[int, float]
|
Displacement from equilibrium in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Elastic PE in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If k is not positive. |
Example
elastic_potential_energy(200, 0.1) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
electric_field_parallel_plate(voltage: Union[int, float], distance: Union[int, float]) -> float
¶
Calculate uniform electric field between parallel plates E = V/d.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voltage
|
Union[int, float]
|
Potential difference in volts. |
required |
distance
|
Union[int, float]
|
Plate separation in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Electric field in V/m. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If distance is not positive. |
Example
electric_field_parallel_plate(1000, 0.01) 100000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
electric_field_point(charge: Union[int, float], distance: Union[int, float]) -> float
¶
Calculate the electric field magnitude from a point charge: E = k·|q|/r².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge
|
Union[int, float]
|
Charge in Coulombs. |
required |
distance
|
Union[int, float]
|
Distance from charge in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Electric field magnitude in N/C (= V/m). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If distance is not positive. |
Example
round(electric_field_point(1e-6, 0.1), 2) 898755.18
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
electric_potential(charge: Union[int, float], distance: Union[int, float]) -> float
¶
Calculate electric potential V = k·q/r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge
|
Union[int, float]
|
Point charge in coulombs. |
required |
distance
|
Union[int, float]
|
Distance from charge in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Electric potential in volts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If distance is not positive. |
Example
round(electric_potential(1e-6, 0.1), 2) 89875.52
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
energy_convert(value: Union[int, float], from_unit: str, to_unit: str) -> float
¶
Converts an energy value between common units.
Supported units: j, kj, mj, cal, kcal, wh, kwh, btu, ev, ft_lbf, erg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[int, float]
|
The numeric value to convert. |
required |
from_unit
|
str
|
Source unit (case-insensitive). |
required |
to_unit
|
str
|
Target unit (case-insensitive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The converted energy value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not numeric or units are not strings. |
ValueError
|
If a unit is not recognised. |
Example
round(energy_convert(1, 'kwh', 'j')) 3600000
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
escape_velocity(mass: Union[int, float], radius: Union[int, float]) -> float
¶
Computes the escape velocity from a celestial body.
v = √(2 × G × M / r).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass of the body in kilograms. |
required |
radius
|
Union[int, float]
|
Radius (distance from centre) in metres (must be positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Escape velocity in m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass is negative or radius is not positive. |
Example
round(escape_velocity(5.972e24, 6.371e6), 0) 11185.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
float_to_int_truncated(number: float) -> int
¶
Converts a float to an integer by truncating the decimal part (towards zero).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
float
|
The float number to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The resulting integer without the decimal part. |
Example
float_to_int_truncated(3.9) 3 float_to_int_truncated(-3.9) -3 float_to_int_truncated(5.0) 5
Cost: O(1), direct type conversion via truncation.
Source code in shortfx/fxNumeric/conversion_functions.py
float_to_json_safe(float_value: float) -> str
¶
Converts a floating-point number to a JSON-safe representation.
Description
JSON does not support NaN or Infinity. This function converts them to string representations before serialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
float_value
|
float
|
The input floating-point number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The number as a valid JSON string. |
Usage Example
float_to_json_safe(3.14) '3.14' float_to_json_safe(float('nan')) '"NaN"'
Cost: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
focal_length(object_distance: Union[int, float], image_distance: Union[int, float]) -> float
¶
Calculate focal length using the thin lens equation: 1/f = 1/do + 1/di.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_distance
|
Union[int, float]
|
Distance from lens to object in meters. |
required |
image_distance
|
Union[int, float]
|
Distance from lens to image in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Focal length in meters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If the sum of reciprocals is zero (no focal point). |
Example
round(focal_length(0.3, 0.6), 1) 0.2
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
foot_pounds_to_newton_meters(ftlb: float) -> float
¶
Convert foot-pounds to newton-metres (torque).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ftlb
|
float
|
Torque in ft·lbf. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Torque in N·m. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ftlb is not numeric. |
Usage Example
round(foot_pounds_to_newton_meters(0.7376), 4) 1.0001
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
fraction_to_decimal(numerator: int, denominator: int) -> float
¶
Convert a fraction to its decimal representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numerator
|
int
|
Numerator of the fraction. |
required |
denominator
|
int
|
Denominator of the fraction. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Float result of numerator / denominator. |
Raises:
| Type | Description |
|---|---|
ZeroDivisionError
|
If denominator is 0. |
Example
fraction_to_decimal(3, 4) 0.75 fraction_to_decimal(22, 7) 3.142857142857143
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
free_space_path_loss(freq: Union[int, float], distance: Union[int, float]) -> float
¶
Calculate free-space path loss in decibels.
Description
FSPL(dB) = 20·log₁₀(d) + 20·log₁₀(f) + 20·log₁₀(4π/c). Used for radio link budget planning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
Union[int, float]
|
Frequency in hertz (must be positive). |
required |
distance
|
Union[int, float]
|
Distance in meters (must be positive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Path loss in decibels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If freq or distance is not positive. |
Example
round(free_space_path_loss(2.4e9, 100), 2) 80.05
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
freq_from_wavelength(wavelength_m: Union[int, float], velocity: Union[int, float] = 299792458.0) -> float
¶
Calculate frequency from wavelength.
Description
f = velocity / wavelength. Inverse of wavelength().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength_m
|
Union[int, float]
|
Wavelength in meters (must be positive). |
required |
velocity
|
Union[int, float]
|
Propagation speed in m/s (default: speed of light). |
299792458.0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Frequency in hertz. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If wavelength_m is not positive. |
Example
freq_from_wavelength(0.299792458) 1000000000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
frequency_to_wavelength(frequency_hz: float) -> float
¶
Convert electromagnetic frequency to wavelength.
λ = c / f, where c = 299 792 458 m/s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency_hz
|
float
|
Frequency in hertz (positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Wavelength in metres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If frequency_hz is not numeric. |
ValueError
|
If frequency_hz <= 0. |
Example
round(frequency_to_wavelength(100e6), 4) 2.9979
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
friction_force(normal_force: Union[int, float], coefficient: Union[int, float]) -> float
¶
Calculate friction force: F_f = μ * N.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normal_force
|
Union[int, float]
|
Normal force in Newtons. |
required |
coefficient
|
Union[int, float]
|
Coefficient of friction (static or kinetic). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Friction force in Newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If coefficient is negative. |
Example
friction_force(100, 0.5) 50.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
friis_transmission(pt: Union[int, float], gt: Union[int, float], gr: Union[int, float], wavelength_m: Union[int, float], distance: Union[int, float]) -> float
¶
Calculate received power using the Friis transmission equation.
Description
Pr = Pt × Gt × Gr × (λ / (4πd))². Fundamental equation for free-space radio link budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pt
|
Union[int, float]
|
Transmitted power in watts (must be positive). |
required |
gt
|
Union[int, float]
|
Transmit antenna gain (linear, not dB). |
required |
gr
|
Union[int, float]
|
Receive antenna gain (linear, not dB). |
required |
wavelength_m
|
Union[int, float]
|
Signal wavelength in meters (must be positive). |
required |
distance
|
Union[int, float]
|
Distance between antennas in meters (must be positive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Received power in watts. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any parameter is not positive. |
Example
round(friis_transmission(1.0, 1.0, 1.0, 0.03, 1000), 12) 6e-12
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
froude_number(v: Union[int, float], g: Union[int, float], length: Union[int, float]) -> float
¶
Calculate the Froude number Fr = v / √(g · L).
Dimensionless number comparing flow inertia to gravity effects in open-channel hydraulics and ship hydrodynamics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
Union[int, float]
|
Flow velocity (m/s). |
required |
g
|
Union[int, float]
|
Gravitational acceleration (m/s²). |
required |
length
|
Union[int, float]
|
Characteristic length (m). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Froude number (dimensionless). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If g or length are non-positive. |
Example
round(froude_number(5, 9.81, 2), 4) 1.1288
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
gallons_to_liters(gallons: float, us: bool = True) -> float
¶
Convert gallons to litres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gallons
|
float
|
Volume in gallons. |
required |
us
|
bool
|
If True use US gallon (3.78541), else imperial (4.54609). |
True
|
Returns:
| Type | Description |
|---|---|
float
|
Volume in litres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If gallons is not numeric. |
Usage Example
round(gallons_to_liters(1), 4) 3.7854
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
gay_lussac_pressure(p1: Union[int, float], t1: Union[int, float], t2: Union[int, float]) -> float
¶
Return the new pressure using Gay-Lussac's law.
At constant volume: P₁ / T₁ = P₂ / T₂ ⟹ P₂ = P₁ · T₂ / T₁. Temperatures in kelvins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Union[int, float]
|
Initial pressure (must be > 0). |
required |
t1
|
Union[int, float]
|
Initial temperature in K (must be > 0). |
required |
t2
|
Union[int, float]
|
Final temperature in K (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Final pressure as a float. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0. |
Example
gay_lussac_pressure(100_000, 300, 600) 200000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
gradians_to_degrees(grad: float) -> float
¶
Convert gradians (gon) to degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grad
|
float
|
Angle in gradians. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle in degrees. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If grad is not numeric. |
Usage Example
gradians_to_degrees(100) 90.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
grams_to_troy_ounces(grams: float) -> float
¶
Convert grams to troy ounces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grams
|
float
|
Mass in grams. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mass in troy ounces. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If grams is not numeric. |
Usage Example
round(grams_to_troy_ounces(31.1035), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
grashof_number(gravity: Union[int, float], beta_coeff: Union[int, float], delta_temp: Union[int, float], length: Union[int, float], kinematic_viscosity: Union[int, float]) -> float
¶
Return the Grashof number for natural convection.
Gr = g · β · ΔT · L³ / ν².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s² (> 0). |
required |
beta_coeff
|
Union[int, float]
|
Thermal expansion coefficient in 1/K (> 0). |
required |
delta_temp
|
Union[int, float]
|
Temperature difference in K (must be > 0). |
required |
length
|
Union[int, float]
|
Characteristic length in metres (> 0). |
required |
kinematic_viscosity
|
Union[int, float]
|
Kinematic viscosity in m²/s (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Grashof number (dimensionless). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0. |
Example
round(grashof_number(9.81, 3.41e-3, 20, 0.5, 1.5e-5), 0) 371690000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
gravitational_force(m1: Union[int, float], m2: Union[int, float], distance: Union[int, float]) -> float
¶
Computes gravitational force via Newton's law.
F = G × m1 × m2 / d².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m1
|
Union[int, float]
|
Mass 1 in kilograms. |
required |
m2
|
Union[int, float]
|
Mass 2 in kilograms. |
required |
distance
|
Union[int, float]
|
Distance between centres in metres (must be positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Force in newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If distance is zero or negative, or masses are negative. |
Example
round(gravitational_force(5.972e24, 80, 6.371e6), 2) 789.54
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
gravitational_potential_energy(mass: Union[int, float], height: Union[int, float], gravity: Union[int, float] = 9.80665) -> float
¶
Calculate gravitational potential energy: U = m·g·h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
height
|
Union[int, float]
|
Height above reference in meters. |
required |
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s² (default 9.80665). |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Potential energy in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass or gravity is not positive. |
Example
gravitational_potential_energy(10, 5) 490.3325
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
h_concentration_to_ph(concentration: float) -> float
¶
Convert hydrogen ion concentration [H⁺] to pH.
Description
pH = −log₁₀([H⁺]). Inverse of ph_to_h_concentration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
concentration
|
float
|
Hydrogen ion concentration in mol/L (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
pH value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If concentration is not numeric. |
ValueError
|
If concentration is not positive. |
Usage Example
h_concentration_to_ph(1e-7) 7.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
half_life_remaining(initial_quantity: Union[int, float], half_life: Union[int, float], elapsed_time: Union[int, float]) -> float
¶
Calculate remaining quantity after radioactive/exponential decay.
N(t) = N₀ * (1/2)^(t / t½)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_quantity
|
Union[int, float]
|
Initial amount. |
required |
half_life
|
Union[int, float]
|
Half-life period (same time units as elapsed_time). |
required |
elapsed_time
|
Union[int, float]
|
Time elapsed. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Remaining quantity. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If initial_quantity or half_life is not positive, or elapsed_time is negative. |
Example
half_life_remaining(100, 5, 10) 25.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
heat_capacity(mass: Union[int, float], specific_heat: Union[int, float], temperature_change: Union[int, float]) -> float
¶
Calculate heat energy Q = m·c·ΔT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
specific_heat
|
Union[int, float]
|
Specific heat capacity in J/(kg·K). |
required |
temperature_change
|
Union[int, float]
|
Temperature change in K. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Heat energy in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass or specific_heat is not positive. |
Example
heat_capacity(2, 4186, 10) 83720.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
heat_engine_efficiency(t_hot: Union[int, float], t_cold: Union[int, float]) -> float
¶
Return the Carnot efficiency of a heat engine.
η = 1 − T_cold / T_hot. Temperatures in kelvins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_hot
|
Union[int, float]
|
Hot reservoir temperature in K (must be > 0). |
required |
t_cold
|
Union[int, float]
|
Cold reservoir temperature in K (must be ≥ 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Carnot efficiency as a float (0–1). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If t_hot ≤ 0, t_cold < 0, or t_cold ≥ t_hot. |
Example
round(heat_engine_efficiency(600, 300), 2) 0.5
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
heat_index(temperature_c: Union[int, float], relative_humidity: Union[int, float]) -> float
¶
Calculate heat index (feels-like temperature) in Celsius.
Uses the Rothfusz regression equation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature_c
|
Union[int, float]
|
Air temperature in Celsius (>= 27). |
required |
relative_humidity
|
Union[int, float]
|
Relative humidity in percent (0-100). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Heat index in Celsius. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If temperature < 27 or humidity not in [0, 100]. |
Example
round(heat_index(35, 75), 1) 53.3
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
heat_transfer_conduction(thermal_conductivity: Union[int, float], area: Union[int, float], temperature_diff: Union[int, float], thickness: Union[int, float]) -> float
¶
Calculate heat transfer rate by conduction (Fourier's law): Q = k·A·ΔT/L.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thermal_conductivity
|
Union[int, float]
|
Thermal conductivity in W/(m·K). |
required |
area
|
Union[int, float]
|
Cross-sectional area in m². |
required |
temperature_diff
|
Union[int, float]
|
Temperature difference in K. |
required |
thickness
|
Union[int, float]
|
Material thickness in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Heat transfer rate in Watts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If thermal_conductivity, area, or thickness not positive. |
Example
heat_transfer_conduction(200, 0.01, 50, 0.1) 1000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
hectares_to_acres(hectares: float) -> float
¶
Convert hectares to acres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hectares
|
float
|
Area in hectares. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area in acres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If hectares is not numeric. |
Usage Example
round(hectares_to_acres(1), 4) 2.4711
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
hertz_to_rpm(hz: float) -> float
¶
Convert hertz to revolutions per minute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hz
|
float
|
Frequency in Hz. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Frequency in RPM. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If hz is not numeric. |
Usage Example
hertz_to_rpm(1) 60.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
hex_to_bin(hexadecimal: str) -> str
¶
Converts a hexadecimal string to binary.
Description
Parses a hexadecimal string and returns its binary representation. Equivalent to Excel HEX2BIN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hexadecimal
|
str
|
A hexadecimal string (optional '0x' prefix). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Binary string without prefix. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not a string. |
ValueError
|
If the string contains invalid hex digits. |
Example
hex_to_bin('FF') '11111111' hex_to_bin('A') '1010'
Complexity: O(n)
Source code in shortfx/fxNumeric/conversion_functions.py
hex_to_int(hex_string: str) -> int
¶
Converts a hexadecimal string to an integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_string
|
str
|
The hexadecimal string (may have '0x' prefix). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The decimal integer. |
Example
hex_to_int("0xff") 255 hex_to_int("FF") 255 hex_to_int("a") 10
Cost: O(n), where n is the length of the hexadecimal string.
Source code in shortfx/fxNumeric/conversion_functions.py
hex_to_oct(hexadecimal: str) -> str
¶
Converts a hexadecimal string to octal.
Description
Parses a hexadecimal string and returns its octal representation. Equivalent to Excel HEX2OCT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hexadecimal
|
str
|
A hexadecimal string (optional '0x' prefix). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Octal string without prefix. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not a string. |
ValueError
|
If the string contains invalid hex digits. |
Example
hex_to_oct('FF') '377' hex_to_oct('1F') '37'
Complexity: O(n)
Source code in shortfx/fxNumeric/conversion_functions.py
hookes_law(spring_constant: Union[int, float], displacement: Union[int, float]) -> float
¶
Calculate the restoring force of a spring using Hooke's law: F = -k * x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spring_constant
|
Union[int, float]
|
Spring constant k in N/m (positive). |
required |
displacement
|
Union[int, float]
|
Displacement x in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Restoring force in Newtons (negative sign indicates opposite direction). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If spring_constant is not positive. |
Example
hookes_law(100, 0.05) -5.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
horsepower_to_watts(hp: float) -> float
¶
Convert mechanical horsepower to watts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hp
|
float
|
Power in horsepower. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Power in watts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If hp is not numeric. |
Usage Example
round(horsepower_to_watts(1), 2) 745.7
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
hsl_to_rgb(h: float, s: float, lightness: float) -> tuple[int, int, int]
¶
Convert HSL colour to RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
float
|
Hue in [0, 360). |
required |
s
|
float
|
Saturation in [0, 1]. |
required |
lightness
|
float
|
Lightness in [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
Tuple |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If values are out of range. |
Example
hsl_to_rgb(0.0, 1.0, 0.5) (255, 0, 0)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
hsv_to_rgb(h: float, s: float, v: float) -> tuple
¶
Convert HSV colour to RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
float
|
Hue in [0, 360). |
required |
s
|
float
|
Saturation in [0, 1]. |
required |
v
|
float
|
Value in [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple (r, g, b) with values in 0–255. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If values are out of range. |
Usage Example
hsv_to_rgb(30.0, 1.0, 1.0) (255, 128, 0)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
ideal_gas_pressure(moles: Union[int, float], temperature_k: Union[int, float], volume_m3: Union[int, float]) -> float
¶
Calculate pressure using the ideal gas law: P = nRT / V.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moles
|
Union[int, float]
|
Amount of substance in moles. |
required |
temperature_k
|
Union[int, float]
|
Temperature in Kelvin. |
required |
volume_m3
|
Union[int, float]
|
Volume in cubic meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure in Pascals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If any input is not positive. |
Example
round(ideal_gas_pressure(1, 273.15, 0.0224), 0) 101388.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
ieee754_hex_representation(numero: float) -> str
¶
Returns the hexadecimal representation of a floating-point number according to the IEEE 754 standard.
This method shows the actual IEEE (underlying binary) value of a float, which can be useful for debugging or understanding how floating-point numbers are stored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numero
|
float
|
The floating-point number for which to obtain the hexadecimal representation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representing the IEEE 754 hexadecimal value of the number.
The format is '0x |
Example
ieee754_hex_representation(3.14) '0x1.91eb851eb851fp+1' ieee754_hex_representation(0.5) '0x1.0p-1' ieee754_hex_representation(1.0) '0x1.0p+0' ieee754_hex_representation(-1.0) '-0x1.0p+0' ieee754_hex_representation(float('inf')) 'inf' ieee754_hex_representation(float('-inf')) '-inf' ieee754_hex_representation(float('nan')) 'nan'
Cost: O(1), call to the float's hex() method.
Source code in shortfx/fxNumeric/conversion_functions.py
impedance_parallel(z1: complex, z2: complex) -> complex
¶
Calculate parallel combination of two impedances.
Description
Z_total = (Z1 × Z2) / (Z1 + Z2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z1
|
complex
|
First impedance (complex, in ohms). |
required |
z2
|
complex
|
Second impedance (complex, in ohms). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
complex |
complex
|
Equivalent parallel impedance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sum of impedances is zero. |
Example
impedance_parallel(100+0j, 100+0j) (50+0j)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
impedance_series(r: Union[int, float], l: Union[int, float], c: Union[int, float], freq: Union[int, float]) -> complex
¶
Calculate impedance of a series RLC circuit.
Description
Z = R + j(2πfL − 1/(2πfC)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
Union[int, float]
|
Resistance in ohms. |
required |
l
|
Union[int, float]
|
Inductance in henrys. |
required |
c
|
Union[int, float]
|
Capacitance in farads (must be positive). |
required |
freq
|
Union[int, float]
|
Frequency in hertz (must be positive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
complex |
complex
|
Impedance in ohms. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If freq or c is not positive. |
Example
z = impedance_series(100, 0.01, 1e-6, 1000) round(z.real, 2) 100.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
impedance_series_rlc(resistance: Union[int, float], inductive_react: Union[int, float], capacitive_react: Union[int, float]) -> float
¶
Return the total impedance of a series RLC circuit.
Z = √(R² + (X_L − X_C)²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resistance
|
Union[int, float]
|
Resistance in ohms (must be ≥ 0). |
required |
inductive_react
|
Union[int, float]
|
Inductive reactance X_L in ohms (≥ 0). |
required |
capacitive_react
|
Union[int, float]
|
Capacitive reactance X_C in ohms (≥ 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Impedance magnitude in ohms. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument is negative. |
Example
impedance_series_rlc(100, 150, 50) 141.42135623730951
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
impulse(force: Union[int, float], time_seconds: Union[int, float]) -> float
¶
Calculate impulse: J = F * Δt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
Union[int, float]
|
Applied force in Newtons. |
required |
time_seconds
|
Union[int, float]
|
Duration in seconds. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Impulse in Newton-seconds (N·s). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If time_seconds is not positive. |
Example
impulse(100, 0.5) 50.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
inductive_reactance(frequency: Union[int, float], inductance: Union[int, float]) -> float
¶
Return the inductive reactance of an inductor.
X_L = 2π · f · L.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
Union[int, float]
|
Frequency in hertz (must be > 0). |
required |
inductance
|
Union[int, float]
|
Inductance in henries (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Inductive reactance in ohms. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If frequency or inductance ≤ 0. |
Example
round(inductive_reactance(60, 0.5), 4) 188.4956
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
inductor_energy(inductance: Union[int, float], current: Union[int, float]) -> float
¶
Calculate energy stored in an inductor: E = ½·L·I².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inductance
|
Union[int, float]
|
Inductance in Henrys. |
required |
current
|
Union[int, float]
|
Current in Amperes. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If inductance is not positive. |
Example
inductor_energy(0.01, 5) 0.125
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_binary_clean(number: int) -> str
¶
Converts an integer to its binary representation as a string, without the '0b' prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
The integer to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The binary string. |
Example
int_to_binary_clean(10) '1010' int_to_binary_clean(5) '101'
Cost: O(log n), where n is the value of the number.
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_binary_with_prefix(number: int) -> str
¶
Converts an integer to its binary representation as a string, including the '0b' prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
The integer to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The binary string with prefix. |
Example
int_to_binary_with_prefix(255) '0b11111111' int_to_binary_with_prefix(10) '0b1010'
Cost: O(log n), where n is the value of the number.
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_bytes(integer_value: int, num_bytes: int, byteorder: str = 'big') -> bytes
¶
Converts an integer to a byte sequence.
Description
Useful for binary data transmission, communication protocols, or storing data in binary formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integer_value
|
int
|
The integer to convert. |
required |
num_bytes
|
int
|
The desired number of bytes for the representation. |
required |
byteorder
|
str
|
Byte order ('big' or 'little'). Default is 'big'. |
'big'
|
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The byte representation of the integer. |
Raises:
| Type | Description |
|---|---|
OverflowError
|
If the integer is too large for the specified number of bytes. |
Usage Example
int_to_bytes(123, 2, byteorder='big') b' {' int_to_bytes(256, 2, byteorder='little') b' '
Cost: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_float(number: int) -> float
¶
Converts an integer to a floating-point number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
The integer number to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The resulting float number. |
Example
int_to_float(5) 5.0 int_to_float(-10) -10.0
Cost: O(1), direct integer to float conversion.
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_hex_clean(number: int) -> str
¶
Converts an integer to its hexadecimal representation as a string, without the '0x' prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
The integer to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The hexadecimal string (lowercase). |
Example
int_to_hex_clean(255) 'ff' int_to_hex_clean(10) 'a'
Cost: O(log n), where n is the value of the number.
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_hex_with_prefix(number: int) -> str
¶
Converts an integer to its hexadecimal representation as a string, including the '0x' prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
The integer to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The hexadecimal string with prefix (lowercase). |
Example
int_to_hex_with_prefix(255) '0xff' int_to_hex_with_prefix(10) '0xa'
Cost: O(log n), where n is the value of the number.
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_octal_with_prefix(number: int) -> str
¶
Converts an integer to its octal representation as a string, including the '0o' prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
The integer to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The octal string with prefix. |
Example
int_to_octal_with_prefix(255) '0o377' int_to_octal_with_prefix(15) '0o17'
Cost: O(log n), where n is the value of the number.
Source code in shortfx/fxNumeric/conversion_functions.py
int_to_roman(number: int) -> str
¶
Convert a positive integer to a Roman numeral string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
Integer in [1, 3999]. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Roman numeral string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If number is outside [1, 3999]. |
Example
int_to_roman(14) 'XIV' int_to_roman(2024) 'MMXXIV'
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
is_numeric_type(value: Any) -> bool
¶
Checks if a value is of numeric type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The value to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value is numeric (int, float, Decimal), False otherwise. |
Example
is_numeric_type(42) True is_numeric_type(3.14) True is_numeric_type(Decimal('10.5')) True is_numeric_type("123") False is_numeric_type(None) False
Cost: O(1), type verification using isinstance.
Source code in shortfx/fxNumeric/conversion_functions.py
joules_to_btu(joules: float) -> float
¶
Convert joules to British thermal units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
joules
|
float
|
Energy in joules. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in BTU. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If joules is not numeric. |
Usage Example
round(joules_to_btu(1055.06), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
joules_to_calories(joules: float) -> float
¶
Convert joules to thermochemical calories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
joules
|
float
|
Energy in joules. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in calories. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If joules is not numeric. |
Usage Example
round(joules_to_calories(4184), 2) 1000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
joules_to_kwh(joules: float) -> float
¶
Convert joules to kilowatt-hours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
joules
|
float
|
Energy in joules. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in kWh. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If joules is not numeric. |
Usage Example
round(joules_to_kwh(3600000), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
kilometers_to_light_years(km: float) -> float
¶
Convert kilometres to light-years.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
km
|
float
|
Distance in kilometres. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Distance in light-years. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If km is not numeric. |
Usage Example
round(kilometers_to_light_years(9460730472580.8), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
kinematic_displacement(initial_velocity: Union[int, float], time: Union[int, float], acceleration: Union[int, float]) -> float
¶
Calculate displacement using kinematic equation s = v₀·t + ½·a·t².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_velocity
|
Union[int, float]
|
Initial velocity in m/s. |
required |
time
|
Union[int, float]
|
Elapsed time in seconds. |
required |
acceleration
|
Union[int, float]
|
Constant acceleration in m/s². |
required |
Returns:
| Type | Description |
|---|---|
float
|
Displacement in meters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If time is negative. |
Example
kinematic_displacement(10, 5, 2) 75.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
kinetic_energy(mass: Union[int, float], velocity: Union[int, float]) -> float
¶
Computes kinetic energy.
KE = 0.5 × m × v².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kilograms (non-negative). |
required |
velocity
|
Union[int, float]
|
Velocity in m/s. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Kinetic energy in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass is negative. |
Example
kinetic_energy(10, 3) 45.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
kinetic_energy_relativistic(rest_mass: Union[int, float], velocity: Union[int, float]) -> float
¶
Calculate relativistic kinetic energy: KE = (γ - 1)·m·c².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rest_mass
|
Union[int, float]
|
Rest mass in kg. |
required |
velocity
|
Union[int, float]
|
Velocity in m/s (must be < c). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Kinetic energy in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If rest_mass not positive or velocity not in [0, c). |
Example
round(kinetic_energy_relativistic(1.0, 0), 1) 0.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
kmh_to_knots(kmh: float) -> float
¶
Convert kilometres per hour to knots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kmh
|
float
|
Speed in km/h. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Speed in knots. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If kmh is not numeric. |
Usage Example
round(kmh_to_knots(1.852), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
knots_to_kmh(knots: float) -> float
¶
Convert knots to kilometres per hour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
knots
|
float
|
Speed in knots. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Speed in km/h. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If knots is not numeric. |
Usage Example
round(knots_to_kmh(1), 4) 1.852
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
knudsen_number(mean_free_path: float, length: float) -> float
¶
Compute the Knudsen number for rarefied gas dynamics.
Description
Kn = λ / L, the ratio of the molecular mean free path to the characteristic physical length. Determines the flow regime: Kn < 0.01 continuum, 0.01–0.1 slip, 0.1–10 transitional, Kn > 10 free molecular.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean_free_path
|
float
|
Molecular mean free path (m). |
required |
length
|
float
|
Characteristic length (m). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Dimensionless Knudsen number. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If length is zero. |
Usage Example
knudsen_number(6.8e-8, 0.001) 6.8e-05
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
kwh_to_joules(kwh: float) -> float
¶
Convert kilowatt-hours to joules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwh
|
float
|
Energy in kWh. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If kwh is not numeric. |
Usage Example
kwh_to_joules(1) 3600000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
lens_magnification(image_distance: Union[int, float], object_distance: Union[int, float]) -> float
¶
Calculate the magnification of a thin lens: M = -di / do.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_distance
|
Union[int, float]
|
Distance from lens to image. |
required |
object_distance
|
Union[int, float]
|
Distance from lens to object. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Magnification (negative = inverted image). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If object_distance is zero. |
Example
lens_magnification(0.6, 0.3) -2.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
light_years_to_kilometers(ly: float) -> float
¶
Convert light-years to kilometres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ly
|
float
|
Distance in light-years. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Distance in kilometres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ly is not numeric. |
Usage Example
light_years_to_kilometers(1) 9460730472580.8
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
liters_per_minute_to_cubic_meters_per_second(lpm: float) -> float
¶
Convert liters per minute to cubic meters per second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lpm
|
float
|
Flow rate in liters per minute. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Flow rate in m³/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If lpm is not numeric. |
Usage Example
round(liters_per_minute_to_cubic_meters_per_second(60), 6) 0.001
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
liters_to_gallons(liters: float, us: bool = True) -> float
¶
Convert litres to gallons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
liters
|
float
|
Volume in litres. |
required |
us
|
bool
|
If True use US gallon (3.78541), else imperial (4.54609). |
True
|
Returns:
| Type | Description |
|---|---|
float
|
Volume in gallons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If liters is not numeric. |
Usage Example
round(liters_to_gallons(3.78541), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
lorentz_factor(velocity: Union[int, float]) -> float
¶
Calculate the Lorentz factor: γ = 1 / √(1 - v²/c²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[int, float]
|
Object velocity in m/s (must be less than c). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Lorentz factor (≥ 1). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If velocity is not numeric. |
ValueError
|
If velocity is negative or ≥ speed of light. |
Example
round(lorentz_factor(2.0e8), 4) 1.3416
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
lumens_to_candela(lm: float, solid_angle_sr: float = 12.566370614359172) -> float
¶
Convert luminous flux (lumens) to luminous intensity (candela).
Candela = lumens / solid angle (steradians). Default solid angle is 4π sr (full sphere).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lm
|
float
|
Luminous flux in lumens. |
required |
solid_angle_sr
|
float
|
Solid angle in steradians (default 4π). |
12.566370614359172
|
Returns:
| Type | Description |
|---|---|
float
|
Luminous intensity in candela. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If lm or solid_angle_sr is not numeric. |
ValueError
|
If solid_angle_sr is zero. |
Usage Example
round(lumens_to_candela(12.57), 4) 1.0003
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
luminous_flux(candela: float, solid_angle_sr: float = 4 * 3.141592653589793) -> float
¶
Convert luminous intensity (candela) to luminous flux (lumens).
Φ = I × Ω, where Ω is the solid angle in steradians. Default Ω = 4π (full sphere).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candela
|
float
|
Luminous intensity in candela. |
required |
solid_angle_sr
|
float
|
Solid angle in steradians (default 4π). |
4 * 3.141592653589793
|
Returns:
| Type | Description |
|---|---|
float
|
Luminous flux in lumens. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If candela or solid_angle_sr is negative. |
Example
round(luminous_flux(1.0), 2) 12.57
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
mach_number(velocity: Union[int, float], speed_of_sound: Union[int, float] = 343.0) -> float
¶
Calculate the Mach number: M = v / c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[int, float]
|
Object velocity in m/s. |
required |
speed_of_sound
|
Union[int, float]
|
Speed of sound in the medium in m/s (default 343 for air at 20 °C). |
343.0
|
Returns:
| Type | Description |
|---|---|
float
|
Mach number (dimensionless). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If speed_of_sound is not positive. |
Example
round(mach_number(680), 2) 1.98
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
mach_to_ms(mach: float, speed_of_sound: float = 343.0) -> float
¶
Convert Mach number to metres per second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mach
|
float
|
Mach number. |
required |
speed_of_sound
|
float
|
Speed of sound in m/s (default 343 at sea level). |
343.0
|
Returns:
| Type | Description |
|---|---|
float
|
Speed in m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If mach or speed_of_sound is not numeric. |
Usage Example
mach_to_ms(1) 343.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
magnetic_field_solenoid(n_turns: Union[int, float], current: Union[int, float], length: Union[int, float]) -> float
¶
Calculate magnetic field inside a solenoid B = μ₀·(N/L)·I.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_turns
|
Union[int, float]
|
Number of turns. |
required |
current
|
Union[int, float]
|
Current in amperes. |
required |
length
|
Union[int, float]
|
Length of solenoid in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Magnetic field in tesla. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If n_turns, current, or length not positive. |
Example
round(magnetic_field_solenoid(1000, 2, 0.5), 6) 0.005027
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
magnetic_flux(magnetic_field: Union[int, float], area: Union[int, float], angle: Union[int, float] = 0.0) -> float
¶
Calculate magnetic flux: Φ = B·A·cos(θ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
magnetic_field
|
Union[int, float]
|
Magnetic field strength in Tesla. |
required |
area
|
Union[int, float]
|
Area in m². |
required |
angle
|
Union[int, float]
|
Angle between field and area normal in radians (default 0). |
0.0
|
Returns:
| Type | Description |
|---|---|
float
|
Magnetic flux in Weber. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If area is negative. |
Example
magnetic_flux(0.5, 0.02) 0.01
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
magnetic_flux_density(permeability: Union[int, float], current: Union[int, float], distance: Union[int, float]) -> float
¶
Return the magnetic flux density around a long straight wire.
B = μ · I / (2π · r).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permeability
|
Union[int, float]
|
Magnetic permeability of the medium (H/m, > 0). |
required |
current
|
Union[int, float]
|
Current in amperes (must be > 0). |
required |
distance
|
Union[int, float]
|
Distance from the wire in metres (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Magnetic flux density in tesla. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If any argument ≤ 0. |
Example
round(magnetic_flux_density(1.2566370614e-6, 10, 0.05), 8) 4e-05
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
magnetic_force_charge(charge: Union[int, float], velocity: Union[int, float], magnetic_field: Union[int, float], angle: Union[int, float] = 1.5707963267948966) -> float
¶
Calculate magnetic force on a moving charge F = q·v·B·sin(θ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge
|
Union[int, float]
|
Charge in coulombs. |
required |
velocity
|
Union[int, float]
|
Speed in m/s. |
required |
magnetic_field
|
Union[int, float]
|
Magnetic field in tesla. |
required |
angle
|
Union[int, float]
|
Angle between v and B in radians (default π/2). |
1.5707963267948966
|
Returns:
| Type | Description |
|---|---|
float
|
Force in newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
Example
magnetic_force_charge(1.6e-19, 1e6, 0.5) 8e-14
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
magnetic_force_on_wire(current: Union[int, float], length: Union[int, float], magnetic_field: Union[int, float], angle: Union[int, float] = 1.5707963267948966) -> float
¶
Calculate force on a current-carrying wire: F = I·L·B·sin(θ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current
|
Union[int, float]
|
Current in Amperes. |
required |
length
|
Union[int, float]
|
Wire length in the field in meters. |
required |
magnetic_field
|
Union[int, float]
|
Magnetic field strength in Tesla. |
required |
angle
|
Union[int, float]
|
Angle between wire and field in radians (default π/2). |
1.5707963267948966
|
Returns:
| Type | Description |
|---|---|
float
|
Force in Newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If length or magnetic_field is negative. |
Example
magnetic_force_on_wire(5, 0.2, 0.3) 0.3
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
moment_of_inertia_point(mass: Union[int, float], radius: Union[int, float]) -> float
¶
Calculate moment of inertia for a point mass I = m·r².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
radius
|
Union[int, float]
|
Distance from rotation axis in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia in kg·m². |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass is not positive. |
Example
moment_of_inertia_point(5, 3) 45.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
momentum(mass: Union[int, float], velocity: Union[int, float]) -> float
¶
Calculate linear momentum: p = m * v.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
velocity
|
Union[int, float]
|
Velocity in m/s (can be negative for direction). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Momentum in kg·m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass is not positive. |
Example
momentum(10, 5) 50.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
ms_to_mach(ms: float, speed_of_sound: float = 343.0) -> float
¶
Convert metres per second to Mach number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ms
|
float
|
Speed in m/s. |
required |
speed_of_sound
|
float
|
Speed of sound in m/s (default 343 at sea level). |
343.0
|
Returns:
| Type | Description |
|---|---|
float
|
Mach number. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ms or speed_of_sound is not numeric. |
ValueError
|
If speed_of_sound is zero. |
Usage Example
ms_to_mach(343) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
nernst_potential(z: int, concentration_out: Union[int, float], concentration_in: Union[int, float], temperature: Union[int, float] = 310.15) -> float
¶
Return the Nernst equilibrium potential for an ion.
E = (R · T) / (z · F) · ln(C_out / C_in).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
int
|
Ion valence (charge number, ≠ 0). |
required |
concentration_out
|
Union[int, float]
|
Extracellular concentration (> 0). |
required |
concentration_in
|
Union[int, float]
|
Intracellular concentration (> 0). |
required |
temperature
|
Union[int, float]
|
Temperature in kelvins (default 310.15 = 37 °C). |
310.15
|
Returns:
| Type | Description |
|---|---|
float
|
Equilibrium potential in volts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments have wrong types. |
ValueError
|
If concentrations ≤ 0 or z is zero. |
Example
round(nernst_potential(1, 145, 12) * 1000, 1) 66.6
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
newton_meters_to_foot_pounds(nm: float) -> float
¶
Convert newton-metres to foot-pounds (torque).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nm
|
float
|
Torque in N·m. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Torque in ft·lbf. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If nm is not numeric. |
Usage Example
round(newton_meters_to_foot_pounds(1), 4) 0.7376
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
newtons_to_pounds_force(newtons: float) -> float
¶
Convert newtons to pounds-force.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
newtons
|
float
|
Force in newtons. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Force in lbf. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If newtons is not numeric. |
Usage Example
round(newtons_to_pounds_force(4.44822), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
noise_figure_to_temperature(nf_db: float, t0: float = 290.0) -> float
¶
Convert noise figure (dB) to equivalent noise temperature (Kelvin).
T_e = T₀ × (10^(NF/10) − 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nf_db
|
float
|
Noise figure in decibels. |
required |
t0
|
float
|
Reference temperature in Kelvin (default 290 K). |
290.0
|
Returns:
| Type | Description |
|---|---|
float
|
Noise temperature in Kelvin. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If t0 is not positive. |
Example
round(noise_figure_to_temperature(3.0), 1) 288.6
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
number_to_base(number: int, radix: int, min_length: int = 0) -> str
¶
Converts a decimal integer to a string in the specified base.
Description
Converts a non-negative integer to its representation in the given radix (2–36). Optionally pads the result to a minimum length. Equivalent to Excel BASE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
The non-negative integer to convert. |
required |
radix
|
int
|
The target base (2 to 36). |
required |
min_length
|
int
|
Minimum length of the result, zero-padded if needed. |
0
|
Returns:
| Type | Description |
|---|---|
str
|
The string representation of the number in the given base. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If number or radix are not integers. |
ValueError
|
If number is negative or radix is outside 2–36. |
Example
number_to_base(255, 16) 'FF' number_to_base(10, 2, 8) '00001010' number_to_base(100, 8) '144'
Complexity: O(log_radix(number))
Source code in shortfx/fxNumeric/conversion_functions.py
number_to_bool(number: Union[int, float]) -> bool
¶
Converts an integer or float to a boolean value. 0 or 0.0 converts to False; any other number converts to True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
Union[int, float]
|
The number to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
The resulting boolean value. |
Example
number_to_bool(0) False number_to_bool(3.5) True number_to_bool(-1) True number_to_bool(0.0) False
Cost: O(1), direct conversion to boolean value.
Source code in shortfx/fxNumeric/conversion_functions.py
number_to_complex(number: Union[int, float]) -> complex
¶
Converts an integer or float to a complex number with zero imaginary part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
Union[int, float]
|
The number to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
complex |
complex
|
The resulting complex number. |
Example
number_to_complex(4.2) (4.2+0j) number_to_complex(7) (7+0j)
Cost: O(1), direct conversion to complex number.
Source code in shortfx/fxNumeric/conversion_functions.py
number_to_hexadecimal(number_input: Union[int, float]) -> str
¶
Returns a string representing the hexadecimal value of a number.
This function converts an integer or float to its hexadecimal string representation.
For integers, it uses Python's built-in hex() function, which prefixes the
output with '0x'. For floats, it first converts the float to an integer
(by truncating its decimal part) before converting to hexadecimal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number_input
|
Union[int, float]
|
The number to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representing the hexadecimal value, prefixed with '0x'. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not an integer or a float. |
ValueError
|
If the input number is too large to be converted to an integer for hexadecimal representation (relevant for very large floats). |
Example
number_to_hexadecimal(255) '0xff' number_to_hexadecimal(10) '0xa' number_to_hexadecimal(0) '0x0' number_to_hexadecimal(25.75) '0x19' number_to_hexadecimal(-10) '-0xa'
Cost: O(log n), donde n es el valor absoluto del número.
Source code in shortfx/fxNumeric/conversion_functions.py
number_to_octal(number_input: Union[int, float]) -> str
¶
Returns a string representing the octal value of a number.
This function converts an integer or float to its octal string representation.
For integers, it uses Python's built-in oct() function, which prefixes the
output with '0o'. For floats, it first converts the float to an integer
(by truncating its decimal part) before converting to octal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number_input
|
Union[int, float]
|
The number to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representing the octal value, prefixed with '0o'. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not an integer or a float. |
ValueError
|
If the input number is too large to be converted to an integer for octal representation (relevant for very large floats). |
Example
number_to_octal(8) '0o10' number_to_octal(15) '0o17' number_to_octal(0) '0o0' number_to_octal(10.99) '0o12' number_to_octal(-7) '-0o7'
Cost: O(log n), donde n es el valor absoluto del número.
Source code in shortfx/fxNumeric/conversion_functions.py
number_to_string(number: Union[int, float]) -> str
¶
Converts an integer or float to its string representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
Union[int, float]
|
The number to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resulting string. |
Example
number_to_string(3.14) '3.14' number_to_string(100) '100' number_to_string(-0.5) '-0.5'
Cost: O(1), direct string conversion.
Source code in shortfx/fxNumeric/conversion_functions.py
number_to_words(number: int, lang: str = 'en') -> str
¶
Convert an integer to its written-word representation.
Supports English ('en') and Spanish ('es') for integers in
[-999_999_999_999, 999_999_999_999].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
Integer to convert. |
required |
lang
|
str
|
Language code ( |
'en'
|
Returns:
| Type | Description |
|---|---|
str
|
Written representation as string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If number is out of supported range or lang is unsupported. |
Example
number_to_words(42) 'forty-two' number_to_words(42, 'es') 'cuarenta y dos' number_to_words(0) 'zero'
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
nusselt_number(h: float, length: float, k: float) -> float
¶
Compute the Nusselt number for convective heat transfer.
Description
Nu = h × L / k, where h is the convective heat transfer coefficient, L is the characteristic length, and k is the thermal conductivity of the fluid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
float
|
Convective heat transfer coefficient (W/(m²·K)). |
required |
length
|
float
|
Characteristic length (m). |
required |
k
|
float
|
Thermal conductivity (W/(m·K)). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Dimensionless Nusselt number. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If k is zero. |
Usage Example
nusselt_number(50.0, 0.5, 0.6) 41.666666666666664
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
nyquist_frequency(sample_rate: float) -> float
¶
Returns the Nyquist frequency for a given sample rate.
f_Nyquist = sample_rate / 2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
float
|
Sampling frequency in Hz (positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Nyquist frequency in Hz. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If sample_rate is not numeric. |
ValueError
|
If sample_rate is not positive. |
Example
nyquist_frequency(44100) 22050.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
oct_to_bin(octal: str) -> str
¶
Converts an octal string to binary.
Description
Parses an octal string and returns its binary representation. Equivalent to Excel OCT2BIN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
octal
|
str
|
An octal string (optional '0o' prefix). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Binary string without prefix. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not a string. |
ValueError
|
If the string contains invalid octal digits. |
Example
oct_to_bin('377') '11111111' oct_to_bin('10') '1000'
Complexity: O(n)
Source code in shortfx/fxNumeric/conversion_functions.py
oct_to_hex(octal: str) -> str
¶
Converts an octal string to hexadecimal.
Description
Parses an octal string and returns its hexadecimal representation. Equivalent to Excel OCT2HEX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
octal
|
str
|
An octal string (optional '0o' prefix). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Uppercase hexadecimal string without prefix. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not a string. |
ValueError
|
If the string contains invalid octal digits. |
Example
oct_to_hex('377') 'FF' oct_to_hex('37') '1F'
Complexity: O(n)
Source code in shortfx/fxNumeric/conversion_functions.py
octal_to_int(octal_string: str) -> int
¶
Converts an octal string to an integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
octal_string
|
str
|
The octal string (may have '0o' prefix). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The decimal integer. |
Example
octal_to_int("0o17") 15 octal_to_int("77") 63
Cost: O(n), where n is the length of the octal string.
Source code in shortfx/fxNumeric/conversion_functions.py
ohms_law(voltage: Union[int, float, None] = None, current: Union[int, float, None] = None, resistance: Union[int, float, None] = None) -> float
¶
Solves Ohm's law V = I × R for the missing variable.
Provide exactly two of the three parameters; the third is computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voltage
|
Union[int, float, None]
|
Voltage in volts (V). |
None
|
current
|
Union[int, float, None]
|
Current in amperes (A). |
None
|
resistance
|
Union[int, float, None]
|
Resistance in ohms (Ω). |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The missing quantity. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If provided values are not numeric. |
ValueError
|
If not exactly two parameters are supplied, or divisor is zero. |
Example
ohms_law(voltage=12, resistance=4) 3.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
orbital_period(semi_major_axis: Union[int, float], central_mass: Union[int, float]) -> float
¶
Calculate orbital period using Kepler's third law.
T = 2π √(a³ / (G·M))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
semi_major_axis
|
Union[int, float]
|
Semi-major axis in meters. |
required |
central_mass
|
Union[int, float]
|
Mass of central body in kg. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Orbital period in seconds. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If inputs are not positive. |
Example
round(orbital_period(6.371e6 + 408000, 5.972e24)) 5554
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
parallel_resistance(r1: Union[int, float], r2: Union[int, float]) -> float
¶
Return the equivalent resistance of two resistors in parallel.
R = (R₁ · R₂) / (R₁ + R₂).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r1
|
Union[int, float]
|
First resistance in ohms (must be > 0). |
required |
r2
|
Union[int, float]
|
Second resistance in ohms (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Equivalent parallel resistance in ohms. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If r1 or r2 is not positive. |
Example
round(parallel_resistance(100, 200), 4) 66.6667
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
pascals_to_atmospheres(pa: float) -> float
¶
Convert pascals to standard atmospheres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa
|
float
|
Pressure in pascals. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure in atmospheres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If pa is not numeric. |
Usage Example
round(pascals_to_atmospheres(101325), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
pascals_to_bars(pa: float) -> float
¶
Convert pascals to bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa
|
float
|
Pressure in pascals. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure in bars. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If pa is not numeric. |
Usage Example
pascals_to_bars(100000) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
pascals_to_psi(pa: float) -> float
¶
Convert pascals to pounds per square inch (PSI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa
|
float
|
Pressure in pascals. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure in PSI. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If pa is not numeric. |
Usage Example
round(pascals_to_psi(101325), 3) 14.696
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
pendulum_period(length: Union[int, float], gravity: Union[int, float] = 9.80665) -> float
¶
Calculate the period of a simple pendulum: T = 2π√(L/g).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
Union[int, float]
|
Pendulum length in meters. |
required |
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s² (default 9.80665). |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Period in seconds. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If length or gravity is not positive. |
Example
round(pendulum_period(1.0), 4) 2.0064
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
ph_to_h_concentration(ph: float) -> float
¶
Convert pH to hydrogen ion concentration [H⁺].
Description
[H⁺] = 10^(−pH). Fundamental conversion in chemistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ph
|
float
|
The pH value. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Hydrogen ion concentration in mol/L. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ph is not numeric. |
Usage Example
ph_to_h_concentration(7.0) 1e-07
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
photon_energy(frequency: Union[int, float]) -> float
¶
Calculate the energy of a photon: E = h * f.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
Union[int, float]
|
Frequency in Hz. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Energy in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If frequency is not numeric. |
ValueError
|
If frequency is not positive. |
Example
round(photon_energy(5e14), 20) 3.31e-19
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
photon_momentum(wavelength: Union[int, float]) -> float
¶
Calculate photon momentum p = h/λ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength
|
Union[int, float]
|
Wavelength in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Momentum in kg·m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input is not numeric. |
ValueError
|
If wavelength is not positive. |
Example
round(photon_momentum(500e-9), 30) 1.325e-27
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
planck_radiation_peak(temperature: Union[int, float]) -> float
¶
Return the spectral radiance at the Wien peak wavelength.
Combines Wien's displacement law with the Planck function to give the peak spectral radiance B(λ_max, T).
B_max ≈ 1.2865 × 10⁻⁵ · T⁵ (W/(m²·sr·m)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
Union[int, float]
|
Temperature in kelvins (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Peak spectral radiance in W/(m²·sr·m). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If temperature is not numeric. |
ValueError
|
If temperature is not positive. |
Example
round(planck_radiation_peak(5778), 0) 82850947237685.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
potential_energy(mass: Union[int, float], height: Union[int, float], g: Union[int, float] = 9.80665) -> float
¶
Computes gravitational potential energy.
PE = m × g × h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kilograms (non-negative). |
required |
height
|
Union[int, float]
|
Height in metres. |
required |
g
|
Union[int, float]
|
Gravitational acceleration (default 9.80665 m/s²). |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Potential energy in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass is negative. |
Example
round(potential_energy(10, 5), 4) 490.3325
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
pounds_force_to_newtons(lbf: float) -> float
¶
Convert pounds-force to newtons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lbf
|
float
|
Force in lbf. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Force in newtons. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If lbf is not numeric. |
Usage Example
round(pounds_force_to_newtons(1), 4) 4.4482
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
power_mechanical(work: Union[int, float], time: Union[int, float]) -> float
¶
Calculate mechanical power P = W / t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work
|
Union[int, float]
|
Work done in joules. |
required |
time
|
Union[int, float]
|
Time in seconds. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Power in watts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If time is not positive. |
Example
power_mechanical(1000, 5) 200.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
power_physics(work: Union[int, float], time_seconds: Union[int, float]) -> float
¶
Calculate mechanical power: P = W / t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work
|
Union[int, float]
|
Work done in Joules. |
required |
time_seconds
|
Union[int, float]
|
Time interval in seconds. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Power in Watts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If time_seconds is not positive. |
Example
power_physics(1000, 5) 200.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
power_to_db(ratio: Union[int, float]) -> float
¶
Convert a power ratio to decibels.
Description
Computes 10 × log₁₀(ratio). Equivalent to POWER2DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
Union[int, float]
|
Power ratio (must be positive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Value in decibels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ratio is not positive. |
Example
power_to_db(100) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
prandtl_number(cp: Union[int, float], mu: Union[int, float], k: Union[int, float]) -> float
¶
Calculate the Prandtl number Pr = Cp · μ / k.
Dimensionless number relating momentum diffusivity to thermal diffusivity in heat-transfer problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cp
|
Union[int, float]
|
Specific heat capacity (J/(kg·K)). |
required |
mu
|
Union[int, float]
|
Dynamic viscosity (Pa·s). |
required |
k
|
Union[int, float]
|
Thermal conductivity (W/(m·K)). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Prandtl number (dimensionless). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If k is zero or any value is negative. |
Example
prandtl_number(4182, 0.001, 0.6) 6.97
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
pressure_at_depth(fluid_density: Union[int, float], depth: Union[int, float], gravity: Union[int, float] = 9.80665, surface_pressure: Union[int, float] = 101325.0) -> float
¶
Calculate pressure at a depth in a fluid: P = P₀ + ρ·g·h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fluid_density
|
Union[int, float]
|
Fluid density in kg/m³. |
required |
depth
|
Union[int, float]
|
Depth below surface in meters. |
required |
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s² (default 9.80665). |
9.80665
|
surface_pressure
|
Union[int, float]
|
Atmospheric pressure in Pa (default 101325). |
101325.0
|
Returns:
| Type | Description |
|---|---|
float
|
Pressure in Pascals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If density, depth, or gravity is not positive. |
Example
pressure_at_depth(1000, 10) 199391.5
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
pressure_convert(value: Union[int, float], from_unit: str, to_unit: str) -> float
¶
Converts a pressure value between common units.
Supported units: pa, hpa, kpa, mpa, bar, mbar, atm, torr, mmhg, psi, inhg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[int, float]
|
The numeric value to convert. |
required |
from_unit
|
str
|
Source unit (case-insensitive). |
required |
to_unit
|
str
|
Target unit (case-insensitive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The converted pressure value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not numeric or units are not strings. |
ValueError
|
If a unit is not recognised. |
Example
round(pressure_convert(1, 'atm', 'psi'), 4) 14.696
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
projectile_max_height(velocity: Union[int, float], angle: Union[int, float], gravity: Union[int, float] = 9.80665) -> float
¶
Calculate the maximum height of a projectile: H = v²·sin²(θ) / (2g).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[int, float]
|
Launch velocity in m/s. |
required |
angle
|
Union[int, float]
|
Launch angle in radians. |
required |
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s². |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Maximum height in meters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If velocity or gravity is not positive. |
Example
import math round(projectile_max_height(20, math.radians(45)), 2) 10.19
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
projectile_range(velocity: Union[int, float], angle: Union[int, float], gravity: Union[int, float] = 9.80665) -> float
¶
Calculate the horizontal range of a projectile (flat ground).
R = v²·sin(2θ) / g
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[int, float]
|
Launch velocity in m/s. |
required |
angle
|
Union[int, float]
|
Launch angle in radians. |
required |
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s². |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Horizontal range in meters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If velocity or gravity is not positive. |
Example
import math round(projectile_range(20, math.radians(45)), 2) 40.77
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
projectile_time_of_flight(velocity: Union[int, float], angle: Union[int, float], gravity: Union[int, float] = 9.80665) -> float
¶
Calculate time of flight for a projectile: T = 2v·sin(θ) / g.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[int, float]
|
Launch velocity in m/s. |
required |
angle
|
Union[int, float]
|
Launch angle in radians. |
required |
gravity
|
Union[int, float]
|
Gravitational acceleration in m/s². |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Time of flight in seconds. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If velocity or gravity is not positive. |
Example
import math round(projectile_time_of_flight(20, math.radians(45)), 4) 2.8837
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
psi_to_pascals(psi: float) -> float
¶
Convert pounds per square inch (PSI) to pascals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
float
|
Pressure in PSI. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pressure in pascals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If psi is not numeric. |
Usage Example
round(psi_to_pascals(14.696), 0) 101325.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
radiation_dose_convert(value: float, from_unit: str, to_unit: str) -> float
¶
Convert between radiation dose units.
Supported units: sv, msv, usv, rem, mrem,
gy, mgy, rad.
Note: Gy-to-Sv conversion assumes a radiation weighting factor of 1 (photons / electrons).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Numeric dose value. |
required |
from_unit
|
str
|
Source unit (case-insensitive). |
required |
to_unit
|
str
|
Target unit (case-insensitive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Converted value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not numeric. |
ValueError
|
If units are not recognized. |
Example
radiation_dose_convert(1, "sv", "rem") 100.0 radiation_dose_convert(500, "mrem", "msv") 5.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
rc_time_constant(resistance: Union[int, float], capacitance: Union[int, float]) -> float
¶
Calculate the RC time constant: τ = R·C.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resistance
|
Union[int, float]
|
Resistance in Ohms. |
required |
capacitance
|
Union[int, float]
|
Capacitance in Farads. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Time constant in seconds. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If either value is not positive. |
Example
rc_time_constant(1000, 0.001) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
relativistic_energy(mass: Union[int, float], velocity: Union[int, float]) -> float
¶
Calculate total relativistic energy E = γ·m·c².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Rest mass in kg. |
required |
velocity
|
Union[int, float]
|
Speed in m/s (must be < c). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total energy in joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass not positive or velocity ≥ c. |
Example
round(relativistic_energy(1, 0), 2) 89875517873681764.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
resistivity_resistance(resistivity: Union[int, float], length: Union[int, float], area: Union[int, float]) -> float
¶
Calculate resistance from resistivity R = ρ·L/A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resistivity
|
Union[int, float]
|
Resistivity in Ω·m. |
required |
length
|
Union[int, float]
|
Conductor length in meters. |
required |
area
|
Union[int, float]
|
Cross-sectional area in m². |
required |
Returns:
| Type | Description |
|---|---|
float
|
Resistance in ohms. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If inputs are not positive. |
Example
resistivity_resistance(1.68e-8, 100, 1e-6) 1.68
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
resistors_parallel_pair(r1: Union[int, float], r2: Union[int, float]) -> float
¶
Calculate equivalent resistance of two resistors in parallel.
R_eq = (R₁·R₂) / (R₁ + R₂)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r1
|
Union[int, float]
|
First resistance in Ohms. |
required |
r2
|
Union[int, float]
|
Second resistance in Ohms. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Equivalent resistance in Ohms. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If either resistance is not positive. |
Example
resistors_parallel_pair(100, 100) 50.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
resonant_freq(l: Union[int, float], c: Union[int, float]) -> float
¶
Calculate resonant frequency of an LC circuit.
Description
f = 1 / (2π√(LC)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l
|
Union[int, float]
|
Inductance in henrys (must be positive). |
required |
c
|
Union[int, float]
|
Capacitance in farads (must be positive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Resonant frequency in hertz. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If l or c is not positive. |
Example
round(resonant_freq(0.01, 1e-6), 2) 1591.55
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
reynolds_number(density: Union[int, float], velocity: Union[int, float], length: Union[int, float], viscosity: Union[int, float]) -> float
¶
Calculate the Reynolds number: Re = ρ * v * L / μ.
Predicts flow patterns: laminar (Re < 2300) or turbulent (Re > 4000).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
density
|
Union[int, float]
|
Fluid density in kg/m³. |
required |
velocity
|
Union[int, float]
|
Flow velocity in m/s. |
required |
length
|
Union[int, float]
|
Characteristic length in meters. |
required |
viscosity
|
Union[int, float]
|
Dynamic viscosity in Pa·s. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Reynolds number (dimensionless). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If density, length, or viscosity is not positive. |
Example
reynolds_number(1000, 1, 0.01, 0.001) 10000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
rgb_to_cmyk(r: int, g: int, b: int) -> tuple
¶
Convert RGB colour to CMYK (Cyan, Magenta, Yellow, Key/Black).
Description
All output channels in [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
int
|
Red channel (0–255). |
required |
g
|
int
|
Green channel (0–255). |
required |
b
|
int
|
Blue channel (0–255). |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple (c, m, y, k). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not an integer. |
ValueError
|
If any channel is outside 0–255. |
Usage Example
rgb_to_cmyk(255, 0, 0) (0.0, 1.0, 1.0, 0.0)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
rgb_to_hsl(r: int, g: int, b: int) -> tuple[float, float, float]
¶
Convert RGB colour to HSL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
int
|
Red (0-255). |
required |
g
|
int
|
Green (0-255). |
required |
b
|
int
|
Blue (0-255). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
Tuple |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not integers. |
ValueError
|
If values are outside [0, 255]. |
Example
rgb_to_hsl(255, 0, 0) (0.0, 1.0, 0.5)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
rgb_to_hsv(r: int, g: int, b: int) -> tuple
¶
Convert RGB colour to HSV (Hue, Saturation, Value).
Description
H in [0, 360), S in [0, 1], V in [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
int
|
Red channel (0–255). |
required |
g
|
int
|
Green channel (0–255). |
required |
b
|
int
|
Blue channel (0–255). |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple (h, s, v). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not an integer. |
ValueError
|
If any channel is outside 0–255. |
Usage Example
rgb_to_hsv(255, 128, 0) (30.11764705882353, 1.0, 1.0)
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
rl_time_constant(inductance: Union[int, float], resistance: Union[int, float]) -> float
¶
Return the RL circuit time constant.
τ = L / R. The time for current to reach ≈ 63.2 % of its final value when a voltage is applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inductance
|
Union[int, float]
|
Inductance in henries (must be > 0). |
required |
resistance
|
Union[int, float]
|
Resistance in ohms (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Time constant in seconds. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If inductance or resistance is not positive. |
Example
rl_time_constant(0.5, 100) 0.005
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
rms_voltage(peak_voltage: Union[int, float]) -> float
¶
Return the root-mean-square voltage from a sinusoidal peak.
V_rms = V_peak / √2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peak_voltage
|
Union[int, float]
|
Peak voltage in volts (must be ≥ 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
RMS voltage in volts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If peak_voltage is not numeric. |
ValueError
|
If peak_voltage is negative. |
Example
round(rms_voltage(325), 2) 229.81
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
roman_to_int(roman: str) -> int
¶
Convert a Roman numeral string to an integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roman
|
str
|
String with valid Roman numeral characters (I, V, X, L, C, D, M). |
required |
Returns:
| Type | Description |
|---|---|
int
|
Integer value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If roman contains invalid characters. |
Example
roman_to_int('XIV') 14 roman_to_int('MMXXIV') 2024
Complexity: O(n) where n = len(roman)
Source code in shortfx/fxNumeric/conversion_functions.py
round_float_to_int(number: float) -> int
¶
Rounds a float to the nearest integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
float
|
The float number to round. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The nearest integer to the given number. If the number is exactly halfway between two integers (e.g., X.5), Python 3.x rounds to the nearest even integer ("banker's rounding"). |
Example
round_float_to_int(3.6) 4 round_float_to_int(3.2) 3 round_float_to_int(3.5) # Rounds to nearest even (4) 4 round_float_to_int(2.5) # Rounds to nearest even (2) 2 round_float_to_int(-3.6) -4 round_float_to_int(-3.5) # Rounds to nearest even (-4) -4
Cost: O(1), rounding via built-in function.
Source code in shortfx/fxNumeric/conversion_functions.py
rpm_to_hertz(rpm: float) -> float
¶
Convert revolutions per minute to hertz.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rpm
|
float
|
Frequency in RPM. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Frequency in Hz. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If rpm is not numeric. |
Usage Example
round(rpm_to_hertz(60), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
safe_convert_number(value: Any, default_value: Union[int, float] = 0, target_type: type = float) -> Union[int, float]
¶
Safely converts an input value to a numeric type (float or int), using a try-except pattern to handle errors and provide a fallback value.
This function handles data input from users or external sources that often contains values that cannot be directly converted to numbers. It prevents program crashes and improves resilience when processing uncertain data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The input value to attempt conversion (can be str, int, float, None, etc.). |
required |
default_value
|
Union[int, float]
|
The value to return if conversion fails. Default is 0. |
0
|
target_type
|
type
|
The numeric type to convert to (int or float). Default is float. |
float
|
Returns:
| Type | Description |
|---|---|
Union[int, float]
|
Union[int, float]: The converted value or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'target_type' is neither 'int' nor 'float'. |
Example
Conversion to float¶
safe_convert_number("3.14") 3.14 safe_convert_number("10") 10.0 safe_convert_number("abc") 0.0 safe_convert_number("") 0.0 safe_convert_number(None) 0.0 safe_convert_number("hello", default_value=-1.0) -1.0
Conversion to int¶
safe_convert_number("5", target_type=int) 5 safe_convert_number("7.8", target_type=int) 7 safe_convert_number("not_a_num", default_value=99, target_type=int) 99 safe_convert_number(None, default_value=1, target_type=int) 1 safe_convert_number(True, target_type=int) # Booleans work 1
Cost: O(1), type conversion with exception handling.
Source code in shortfx/fxNumeric/conversion_functions.py
schwarzschild_radius(mass: Union[int, float]) -> float
¶
Calculate the Schwarzschild radius: r_s = 2GM / c².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Schwarzschild radius in meters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If mass is not numeric. |
ValueError
|
If mass is not positive. |
Example
round(schwarzschild_radius(1.989e30), 0) 2953.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
shannon_capacity(bandwidth: Union[int, float], snr: Union[int, float]) -> float
¶
Calculate Shannon channel capacity.
Description
C = B × log₂(1 + SNR). Theoretical maximum data rate for a communication channel with given bandwidth and signal-to-noise ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth
|
Union[int, float]
|
Channel bandwidth in hertz (must be positive). |
required |
snr
|
Union[int, float]
|
Signal-to-noise ratio (linear, not dB; must be non-negative). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Channel capacity in bits per second. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If bandwidth is not positive or SNR is negative. |
Example
round(shannon_capacity(1e6, 100), 0) 6658211.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
signal_rms(samples: list) -> float
¶
Computes the RMS (Root Mean Square) of a discrete signal.
RMS = √(Σx²/N)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
list
|
List of numeric sample values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
RMS value of the signal. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If samples is not a list. |
ValueError
|
If samples is empty. |
Example
round(signal_rms([1, -1, 1, -1]), 6) 1.0
Complexity: O(N)
Source code in shortfx/fxNumeric/conversion_functions.py
signal_snr_db(signal_power: float, noise_power: float) -> float
¶
Computes the signal-to-noise ratio in decibels.
SNR(dB) = 10 · log₁₀(signal_power / noise_power)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_power
|
float
|
Signal power (positive). |
required |
noise_power
|
float
|
Noise power (positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
SNR in decibels. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If either power is not positive. |
Example
round(signal_snr_db(100, 1), 2) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
signal_to_noise_ratio(signal_power: float, noise_power: float) -> float
¶
Compute the signal-to-noise ratio in decibels.
SNR(dB) = 10 × log₁₀(signal_power / noise_power)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_power
|
float
|
Signal power (positive). |
required |
noise_power
|
float
|
Noise power (positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
SNR in dB. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If either power is not positive. |
Example
round(signal_to_noise_ratio(100, 1), 2) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
skin_depth(freq: Union[int, float], resistivity: Union[int, float], permeability: Union[int, float] = 1.2566370614359173e-06) -> float
¶
Calculate skin depth in a conductor.
Description
δ = √(2ρ / (ωμ)). Determines how far AC penetrates a conductor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
Union[int, float]
|
Frequency in hertz (must be positive). |
required |
resistivity
|
Union[int, float]
|
Electrical resistivity in ohm-meters (must be positive). |
required |
permeability
|
Union[int, float]
|
Magnetic permeability in H/m (default: μ₀). |
1.2566370614359173e-06
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Skin depth in meters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any parameter is not positive. |
Example
round(skin_depth(1e6, 1.68e-8), 6) 6.5e-05
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
snells_law(n1: Union[int, float], theta1: Union[int, float], n2: Union[int, float]) -> float
¶
Computes the refraction angle via Snell's law.
n1 × sin(θ1) = n2 × sin(θ2) → θ2 = arcsin(n1 × sin(θ1) / n2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n1
|
Union[int, float]
|
Refractive index of first medium. |
required |
theta1
|
Union[int, float]
|
Angle of incidence in radians. |
required |
n2
|
Union[int, float]
|
Refractive index of second medium (must be positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle of refraction in radians. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If n2 is not positive or total internal reflection occurs. |
Example
import math round(snells_law(1.0, math.radians(30), 1.5), 6) 0.339837
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
snells_law_angle(n1: Union[int, float], n2: Union[int, float], theta1: Union[int, float]) -> float
¶
Calculate refracted angle using Snell's law: n₁·sin(θ₁) = n₂·sin(θ₂).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n1
|
Union[int, float]
|
Refractive index of first medium. |
required |
n2
|
Union[int, float]
|
Refractive index of second medium. |
required |
theta1
|
Union[int, float]
|
Incident angle in radians. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Refracted angle in radians. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If indices not positive or total internal reflection occurs. |
Example
import math round(snells_law_angle(1.0, 1.5, math.pi / 4), 6) 0.488342
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
sound_intensity_level(intensity: Union[int, float], reference: Union[int, float] = 1e-12) -> float
¶
Calculate sound intensity level in decibels.
β = 10 · log₁₀(I / I₀)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensity
|
Union[int, float]
|
Sound intensity in W/m². |
required |
reference
|
Union[int, float]
|
Reference intensity (default 1e-12 W/m²). |
1e-12
|
Returns:
| Type | Description |
|---|---|
float
|
Sound level in decibels. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If inputs are not positive. |
Example
sound_intensity_level(1e-6) 60.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
specific_heat_energy(mass: Union[int, float], specific_heat: Union[int, float], temperature_change: Union[int, float]) -> float
¶
Calculate thermal energy: Q = m * c * ΔT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Mass in kg. |
required |
specific_heat
|
Union[int, float]
|
Specific heat capacity in J/(kg·K). |
required |
temperature_change
|
Union[int, float]
|
Temperature change in Kelvin (or Celsius). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Thermal energy in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If mass or specific_heat is not positive. |
Example
specific_heat_energy(1, 4186, 10) 41860.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
specific_impulse(thrust: Union[int, float], mass_flow_rate: Union[int, float], gravity: float = 9.80665) -> float
¶
Return the specific impulse of a rocket engine.
Isp = F / (ṁ · g₀). A measure of propellant efficiency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thrust
|
Union[int, float]
|
Thrust force in newtons (must be > 0). |
required |
mass_flow_rate
|
Union[int, float]
|
Propellant mass flow rate in kg/s (> 0). |
required |
gravity
|
float
|
Standard gravity in m/s² (default 9.80665). |
9.80665
|
Returns:
| Type | Description |
|---|---|
float
|
Specific impulse in seconds. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If thrust, mass_flow_rate, or gravity ≤ 0. |
Example
round(specific_impulse(2_000_000, 700), 2) 291.35
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
speed_convert(value: Union[int, float], from_unit: str, to_unit: str) -> float
¶
Converts a speed value between common units.
Supported units: m/s, km/h, mph, ft/s, knot, mach, c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[int, float]
|
The numeric value to convert. |
required |
from_unit
|
str
|
Source unit (case-insensitive). |
required |
to_unit
|
str
|
Target unit (case-insensitive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The converted speed value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not numeric or units are not strings. |
ValueError
|
If a unit is not recognised. |
Example
round(speed_convert(100, 'km/h', 'mph'), 4) 62.1371
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
spring_potential_energy(spring_constant: Union[int, float], displacement: Union[int, float]) -> float
¶
Calculate elastic potential energy: U = ½·k·x².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spring_constant
|
Union[int, float]
|
Spring constant in N/m. |
required |
displacement
|
Union[int, float]
|
Displacement from equilibrium in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Potential energy in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If spring_constant is not positive. |
Example
spring_potential_energy(200, 0.1) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
stefan_boltzmann_power(emissivity: Union[int, float], area: Union[int, float], temperature: Union[int, float]) -> float
¶
Calculate radiated power using Stefan-Boltzmann law: P = ε·σ·A·T⁴.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emissivity
|
Union[int, float]
|
Surface emissivity (0 < ε ≤ 1). |
required |
area
|
Union[int, float]
|
Surface area in m². |
required |
temperature
|
Union[int, float]
|
Absolute temperature in Kelvin. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Radiated power in Watts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If emissivity not in (0,1], area or temperature not positive. |
Example
round(stefan_boltzmann_power(1.0, 1.0, 300), 2) 459.27
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
stefan_boltzmann_temperature(power: float, emissivity: float, area: float) -> float
¶
Calculates temperature from radiated power (inverse Stefan-Boltzmann).
T = (P / (ε · σ · A))^(1/4)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power
|
float
|
Radiated power in Watts. |
required |
emissivity
|
float
|
Surface emissivity (0 < ε ≤ 1). |
required |
area
|
float
|
Surface area in m². |
required |
Returns:
| Type | Description |
|---|---|
float
|
Temperature in Kelvin. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If parameters are not positive or emissivity > 1. |
Example
round(stefan_boltzmann_temperature(500, 0.9, 1.0), 1) 306.4
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
strain(change_in_length: float, original_length: float) -> float
¶
Calculates engineering strain ε = ΔL / L₀.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
change_in_length
|
float
|
Change in length ΔL. |
required |
original_length
|
float
|
Original length L₀ (positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Dimensionless strain. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If original_length is not positive. |
Example
strain(0.005, 1.0) 0.005
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
stress(force: float, area: float) -> float
¶
Calculates mechanical stress σ = F / A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
float
|
Applied force in Newtons. |
required |
area
|
float
|
Cross-sectional area in m². |
required |
Returns:
| Type | Description |
|---|---|
float
|
Stress in Pascals (N/m²). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If area is not positive. |
Example
stress(1000, 0.01) 100000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
strouhal_number(freq: float, length: float, velocity: float) -> float
¶
Compute the Strouhal number for oscillating flow.
Description
St = f × L / v, a dimensionless number describing vortex shedding and oscillating flow mechanisms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
float
|
Frequency of vortex shedding (Hz). |
required |
length
|
float
|
Characteristic length (m). |
required |
velocity
|
float
|
Flow velocity (m/s). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Dimensionless Strouhal number. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If velocity is zero. |
Usage Example
strouhal_number(10.0, 0.1, 5.0) 0.2
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
temperature_convert(value: Union[int, float], from_unit: str, to_unit: str) -> float
¶
Converts a temperature between Celsius, Fahrenheit, and Kelvin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[int, float]
|
The temperature value. |
required |
from_unit
|
str
|
Source unit ("C", "F", or "K"). |
required |
to_unit
|
str
|
Target unit ("C", "F", or "K"). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The converted temperature. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not numeric. |
ValueError
|
If units are invalid or result is below absolute zero. |
Example
temperature_convert(100, "C", "F") 212.0 temperature_convert(32, "F", "C") 0.0 temperature_convert(0, "C", "K") 273.15
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
terminal_velocity(mass: Union[int, float], drag_coefficient: Union[int, float], area: Union[int, float], air_density: Union[int, float] = 1.225) -> float
¶
Calculate terminal velocity of a falling object.
v = sqrt(2 * m * g / (Cd * A * rho))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Union[int, float]
|
Object mass in kg. |
required |
drag_coefficient
|
Union[int, float]
|
Dimensionless drag coefficient. |
required |
area
|
Union[int, float]
|
Cross-sectional area in m². |
required |
air_density
|
Union[int, float]
|
Air density in kg/m³ (default 1.225 at sea level). |
1.225
|
Returns:
| Type | Description |
|---|---|
float
|
Terminal velocity in m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If any input is not positive. |
Example
round(terminal_velocity(80, 1.0, 0.7), 2) 42.78
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
thermal_expansion_length(original_length: Union[int, float], alpha: Union[int, float], delta_temp: Union[int, float]) -> float
¶
Return the change in length due to thermal expansion.
ΔL = L₀ · α · ΔT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_length
|
Union[int, float]
|
Original length in metres (must be > 0). |
required |
alpha
|
Union[int, float]
|
Coefficient of linear thermal expansion (1/K). |
required |
delta_temp
|
Union[int, float]
|
Temperature change in kelvins or °C. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Change in length in metres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If original_length is not positive. |
Example
thermal_expansion_length(2.0, 1.2e-5, 100) 0.0024
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
thermal_noise(bandwidth: Union[int, float], temperature: Union[int, float] = 290.0) -> float
¶
Calculate Johnson-Nyquist thermal noise power.
Description
P = kB × T × B, where kB is the Boltzmann constant. Fundamental noise floor in electronic systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth
|
Union[int, float]
|
Bandwidth in hertz (must be positive). |
required |
temperature
|
Union[int, float]
|
Absolute temperature in kelvin (default: 290 K). |
290.0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Noise power in watts. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If bandwidth or temperature is not positive. |
Example
thermal_noise(1e6, 290) 4.00388105e-15
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
thermal_resistance(length: Union[int, float], thermal_conductivity: Union[int, float], area: Union[int, float]) -> float
¶
Calculate thermal resistance for conduction: R_th = L / (k·A).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
Union[int, float]
|
Material thickness in meters. |
required |
thermal_conductivity
|
Union[int, float]
|
Thermal conductivity in W/(m·K). |
required |
area
|
Union[int, float]
|
Cross-sectional area in m². |
required |
Returns:
| Type | Description |
|---|---|
float
|
Thermal resistance in K/W. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If any value is not positive. |
Example
thermal_resistance(0.1, 200, 0.01) 0.05
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
to_js_safe_integer(number: Union[int, float]) -> Union[int, str]
¶
Converts a number to a JavaScript-safe integer.
If the number is within JavaScript's safe integer range (-(2^53-1) to 2^53-1), it returns a Python int. If it exceeds this range, it returns a string to avoid precision loss in JavaScript, requiring JavaScript to handle it as BigInt or another large number representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
Union[int, float]
|
The integer or float to convert. If float, it will be truncated to integer before checking. |
required |
Returns:
| Type | Description |
|---|---|
Union[int, str]
|
Union[int, str]: The number as int if within JS safe range, or as string if it exceeds that range. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If 'number' is not an int or float. |
Example
to_js_safe_integer(100) 100 to_js_safe_integer(9007199254740991) # JS_MAX_SAFE_INTEGER 9007199254740991 to_js_safe_integer(9007199254740992) # JS_MAX_SAFE_INTEGER + 1 '9007199254740992' to_js_safe_integer(-9007199254740991) # JS_MIN_SAFE_INTEGER -9007199254740991 to_js_safe_integer(-9007199254740992) # JS_MIN_SAFE_INTEGER - 1 '-9007199254740992' to_js_safe_integer(3.14) # Floats are truncated to integers 3 to_js_safe_integer(9007199254740991.99) 9007199254740991
Cost: O(1), integer comparison and conversion.
Source code in shortfx/fxNumeric/conversion_functions.py
torque(force: Union[int, float], lever_arm: Union[int, float], angle: Union[int, float] = 1.5707963267948966) -> float
¶
Calculate torque τ = F·r·sin(θ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
Union[int, float]
|
Applied force in newtons. |
required |
lever_arm
|
Union[int, float]
|
Distance from pivot in meters. |
required |
angle
|
Union[int, float]
|
Angle between force and lever arm in radians (default π/2). |
1.5707963267948966
|
Returns:
| Type | Description |
|---|---|
float
|
Torque in N·m. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If force or lever_arm is negative. |
Example
torque(100, 0.5) 50.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
troy_ounces_to_grams(oz_t: float) -> float
¶
Convert troy ounces to grams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oz_t
|
float
|
Mass in troy ounces. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mass in grams. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If oz_t is not numeric. |
Usage Example
round(troy_ounces_to_grams(1), 4) 31.1035
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
voltage_divider(vin: Union[int, float], r1: Union[int, float], r2: Union[int, float]) -> float
¶
Return the output voltage of a resistive voltage divider.
V_out = V_in · R₂ / (R₁ + R₂).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vin
|
Union[int, float]
|
Input voltage in volts. |
required |
r1
|
Union[int, float]
|
First (series) resistance in ohms (must be > 0). |
required |
r2
|
Union[int, float]
|
Second (shunt) resistance in ohms (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Output voltage in volts. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not numeric. |
ValueError
|
If r1 or r2 is not positive. |
Example
voltage_divider(12, 8000, 4000) 4.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
voltage_to_db(ratio: Union[int, float]) -> float
¶
Convert a voltage/amplitude ratio to decibels.
Description
Computes 20 × log₁₀(ratio). Equivalent to VOLTAGE2DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
Union[int, float]
|
Voltage/amplitude ratio (must be positive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Value in decibels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ratio is not positive. |
Example
voltage_to_db(10) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
watts_to_horsepower(watts: float) -> float
¶
Convert watts to mechanical horsepower.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
watts
|
float
|
Power in watts. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Power in horsepower. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If watts is not numeric. |
Usage Example
round(watts_to_horsepower(745.7), 4) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
wave_frequency(wave_speed: Union[int, float], wavelength: Union[int, float]) -> float
¶
Calculate wave frequency f = v/λ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_speed
|
Union[int, float]
|
Speed of the wave in m/s. |
required |
wavelength
|
Union[int, float]
|
Wavelength in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Frequency in Hz. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If inputs are not positive. |
Example
wave_frequency(340, 0.5) 680.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
wave_speed(frequency: Union[int, float], wavelength_m: Union[int, float]) -> float
¶
Calculate wave speed: v = f * λ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
Union[int, float]
|
Wave frequency in Hz. |
required |
wavelength_m
|
Union[int, float]
|
Wavelength in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Wave speed in m/s. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If either input is not positive. |
Example
wave_speed(440, 0.78) 343.2
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
wavelength(freq: Union[int, float], velocity: Union[int, float] = 299792458.0) -> float
¶
Calculate wavelength from frequency.
Description
λ = velocity / frequency. Defaults to speed of light in vacuum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
Union[int, float]
|
Frequency in hertz (must be positive). |
required |
velocity
|
Union[int, float]
|
Propagation speed in m/s (default: speed of light). |
299792458.0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Wavelength in meters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If freq is not positive. |
Example
wavelength(1e9) 0.299792458
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
wavelength_to_frequency(wavelength_m: float) -> float
¶
Convert electromagnetic wavelength to frequency.
f = c / λ, where c = 299 792 458 m/s (speed of light in vacuum).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength_m
|
float
|
Wavelength in metres (positive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Frequency in hertz. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If wavelength_m is not numeric. |
ValueError
|
If wavelength_m <= 0. |
Example
wavelength_to_frequency(0.5e-6) 599584916000000.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
weber_number(rho: Union[int, float], v: Union[int, float], length: Union[int, float], sigma: Union[int, float]) -> float
¶
Calculate the Weber number We = ρ · v² · L / σ.
Dimensionless number relating inertia to surface tension, important in droplet formation and atomisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
Union[int, float]
|
Fluid density (kg/m³). |
required |
v
|
Union[int, float]
|
Flow velocity (m/s). |
required |
length
|
Union[int, float]
|
Characteristic length (m). |
required |
sigma
|
Union[int, float]
|
Surface tension (N/m). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Weber number (dimensionless). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If sigma is zero or any value is negative. |
Example
weber_number(1000, 2, 0.01, 0.072) 555.5555555555555
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
wien_displacement_peak(temperature: Union[int, float]) -> float
¶
Return the peak wavelength from Wien's displacement law.
λ_max = b / T, where b ≈ 2.8978 × 10⁻³ m·K.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
Union[int, float]
|
Absolute temperature in kelvins (must be > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Peak wavelength in metres. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If temperature is not numeric. |
ValueError
|
If temperature is not positive. |
Example
round(wien_displacement_peak(5778), 10) 5.015e-07
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
wind_chill(temperature_c: Union[int, float], wind_speed_kmh: Union[int, float]) -> float
¶
Calculate wind chill index using the North American formula.
Valid for temperatures at or below 10 °C and wind speeds above 4.8 km/h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature_c
|
Union[int, float]
|
Air temperature in Celsius. |
required |
wind_speed_kmh
|
Union[int, float]
|
Wind speed in km/h. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Wind chill temperature in Celsius. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If temperature > 10 or wind speed <= 4.8. |
Example
round(wind_chill(-5, 30), 2) -13.0
Complexity: O(1)
Source code in shortfx/fxNumeric/conversion_functions.py
work_done(force: Union[int, float], displacement: Union[int, float], angle: Union[int, float] = 0.0) -> float
¶
Calculate work done: W = F·d·cos(θ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
Union[int, float]
|
Force in Newtons. |
required |
displacement
|
Union[int, float]
|
Displacement in meters. |
required |
angle
|
Union[int, float]
|
Angle between force and displacement in radians (default 0). |
0.0
|
Returns:
| Type | Description |
|---|---|
float
|
Work in Joules. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not numeric. |
ValueError
|
If displacement is negative. |
Example
work_done(50, 10) 500.0
Complexity: O(1)