diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-02-28 21:01:26 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-02-28 21:01:26 -0500 |
| commit | 942a6711361c371da0736cc62f0e3e2ed13f341b (patch) | |
| tree | 607afae0b1c3446bbdc76da4b59d24ca24f0d753 | |
| parent | faf14d71cfbac1f21500f4b997441fa03731bf0e (diff) | |
| download | volute-942a6711361c371da0736cc62f0e3e2ed13f341b.zip | |
fraction/percent conversion functions
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | test.c | 3 | ||||
| -rw-r--r-- | test.h | 3 | ||||
| -rw-r--r-- | test_fraction.c | 15 | ||||
| -rw-r--r-- | unit.c | 12 |
5 files changed, 32 insertions, 3 deletions
@@ -5,7 +5,7 @@ SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c OBJ = ${SRC:.c=.o} HDR = microui.h renderer.h widget.h ui.h unit.h engine.h -TEST_SRC = test.c test_angular_speed.c test_pressure.c test_volume.c test_volume_flow_rate.c unit.c +TEST_SRC = test.c test_angular_speed.c test_pressure.c test_volume.c test_volume_flow_rate.c test_fraction.c unit.c TEST_OBJ = ${TEST_SRC:.c=.o} volute: ${OBJ} @@ -9,6 +9,9 @@ main(void) { test_as_deg_per_sec(); test_as_rpm(); + test_percent(); + test_as_percent(); + test_pascal(); test_millibar(); test_kilopascal(); @@ -15,6 +15,9 @@ void test_as_rad_per_sec(void); void test_as_deg_per_sec(void); void test_as_rpm(void); +void test_percent(void); +void test_as_percent(void); + void test_pascal(void); void test_millibar(void); void test_kilopascal(void); diff --git a/test_fraction.c b/test_fraction.c new file mode 100644 index 0000000..726b2fd --- /dev/null +++ b/test_fraction.c @@ -0,0 +1,15 @@ +#include <assert.h> +#include <stdio.h> + +#include "test.h" +#include "unit.h" + +void +test_percent(void) { + test(percent(12.345), 0.12345); +} + +void +test_as_percent(void) { + test(as_percent(percent(12.345)), 12.345); +} @@ -45,8 +45,16 @@ double as_rpm(AngularSpeed x) { return x * 60.0 / (2.0 * M_PI); } -Fraction percent(double x); -double as_percent(Fraction x); + +Fraction +percent(double x) { + return x / 100.0; +} + +double +as_percent(Fraction x) { + return x * 100.0; +} Pressure |