Spydr06 / CSpydr

A static typed low-level compiled programming language inspired by Rust and C
MIT License
84 stars 2 forks source link

Odd behaviour with floats & printf #16

Open Its-Kenta opened 1 year ago

Its-Kenta commented 1 year ago

I've encountered an odd behaviour with floats and printf where the output returned is not the value you've provided: We have the following code:

import "std.csp";

fn main(): i32 {
    using std::io;

    macro PI { 3.14159265358979323846 }
    let pi: f32 = 1.2;
    let num: i32 = 55;

    printf("%i\n", num);
    printf("%f\n", PI!);
    printf("%f\n", pi);
    <- 0;
}

The output is:

55
3.0000000000
1.0000000000

Does CSpydr not use the same formatting rule as C? Is there something done wrong in this example or there is a deeper underlying problem causing this? As you can see, the integer is printed out fine.

Spydr06 commented 1 year ago

floats should work like they do in C, but some stuff is broken right now :(

Its-Kenta commented 1 year ago

Well, that a bummer. I will have to postpone my binding work until this gets fixed in that case.

Spydr06 commented 1 year ago

you can try the same with libc::printf, in case it's just a bug in fmt.csp, you'll have to import "libc/stdio.csp" tho

Its-Kenta commented 1 year ago

you can try the same with libc::printf, in case it's just a bug in fmt.csp, you'll have to import "libc/stdio.csp" tho

Unfortunately same issue. If anything libc ver spews only 0's.

Spydr06 commented 1 year ago

does it still occur when transpiling to C? (with the -t compiler option)

Its-Kenta commented 1 year ago

does it still occur when transpiling to C? (with the -t compiler option)

No, it seems like transpiling to C works.

Spydr06 commented 1 year ago

Then it's a bug in the assembly generator I'll have to fix.