Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behaviour with floats & printf #16

Open
Its-Kenta opened this issue May 6, 2023 · 7 comments
Open

Odd behaviour with floats & printf #16

Its-Kenta opened this issue May 6, 2023 · 7 comments

Comments

@Its-Kenta
Copy link
Contributor

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
Copy link
Owner

Spydr06 commented May 6, 2023

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

@Its-Kenta
Copy link
Contributor Author

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

@Spydr06
Copy link
Owner

Spydr06 commented May 6, 2023

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
Copy link
Contributor Author

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
Copy link
Owner

Spydr06 commented May 6, 2023

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

@Its-Kenta
Copy link
Contributor Author

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

No, it seems like transpiling to C works.

@Spydr06
Copy link
Owner

Spydr06 commented May 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants