// menggunakan tipe data float64 dari config.rs
use crate::config::{Float, EPSILON};
/// Menghitung tegangan (V) berdasarkan arus (I) dan hambatan (R).
///
/// # Examples
///
/// ```
/// use phyrust::electricity;
/// let current = 2.0;
/// let resistance = 10.0;
/// let v = electricity::voltage(current, resistance);
///```
///

// rumus tegangan
pub fn voltage(current: Float, resistance: Float) -> Float {
    current * resistance
}

// rumus arus
pub fn current(voltage: Float, resistance: Float) -> Float {
    if resistance.abs() < EPSILON {
        return 0.0;
    }
    voltage / resistance
}

// rumus hambatan
pub fn resistance(voltage: Float, current: Float) -> Float {
    if current.abs() < EPSILON {
        return 0.0;
    }
    voltage / current
}

// rumus daya
pub fn power(voltage: Float, current: Float) -> Float {
    voltage * current
}
