feat: add floats

This commit is contained in:
2026-04-22 22:21:26 +02:00
parent c2fc11bbeb
commit e66a4ee736
14 changed files with 471 additions and 66 deletions
+24
View File
@@ -0,0 +1,24 @@
[code]
fn is_less_f64(x: f64, y: f64) -> bool {
return x < y;
}
fn is_greater_eq_f32(x: f32, y: f32) -> bool {
return x >= y;
}
[harness]
#include <stdbool.h>
extern bool is_less_f64(double x, double y);
extern bool is_greater_eq_f32(float x, float y);
int main() {
if (!is_less_f64(3.14, 5.0)) return 1;
if (is_less_f64(5.0, 3.14)) return 2;
if (!is_greater_eq_f32(2.5f, 2.5f)) return 3;
return 0;
}
[expected_return_code]
0
+20
View File
@@ -0,0 +1,20 @@
[code]
fn test_f32(x: f32, y: f32) -> f32 {
let z: f32 = 1.5;
// (4.0 + 2.0) * 1.5 - (4.0 / 2.0) = 6.0 * 1.5 - 2.0 = 9.0 - 2.0 = 7.0
return (x + y) * z - (x / y);
}
[harness]
extern float test_f32(float x, float y);
int main() {
float result = test_f32(4.0f, 2.0f);
if (result == 7.0f) {
return 0;
}
return 1;
}
[expected_return_code]
0
+20
View File
@@ -0,0 +1,20 @@
[code]
fn test_f64(x: f64, y: f64) -> f64 {
let z: f64 = 2.5;
// (7.0 - 2.0) / 2.5 + (7.0 * 2.0) = 5.0 / 2.5 + 14.0 = 2.0 + 14.0 = 16.0
return (x - y) / z + (x * y);
}
[harness]
extern double test_f64(double x, double y);
int main() {
double result = test_f64(7.0, 2.0);
if (result == 16.0) {
return 0;
}
return 1;
}
[expected_return_code]
0
+17
View File
@@ -0,0 +1,17 @@
[code]
fn test_exponents() -> f64 {
let a: f64 = 1e3;
let b: f64 = 2.5e-1;
return a * b; // 1000.0 * 0.25 = 250.0
}
[harness]
extern double test_exponents();
int main() {
if (test_exponents() == 250.0) return 0;
return 1;
}
[expected_return_code]
0
+21
View File
@@ -0,0 +1,21 @@
[code]
fn negate_f32(x: f32) -> f32 {
return -x;
}
fn negate_f64(x: f64) -> f64 {
return -x;
}
[harness]
extern float negate_f32(float x);
extern double negate_f64(double x);
int main() {
if (negate_f32(3.5f) != -3.5f) return 1;
if (negate_f64(-4.2) != 4.2) return 2;
return 0;
}
[expected_return_code]
0