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

String interpolation(floating %g) does not consist to C version #22424

Closed
kbkpbot opened this issue Oct 6, 2024 · 1 comment
Closed

String interpolation(floating %g) does not consist to C version #22424

kbkpbot opened this issue Oct 6, 2024 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@kbkpbot
Copy link
Contributor

kbkpbot commented Oct 6, 2024

Describe the bug

String interpolation of float precision( %g) should consist to it's C version.

Reproduction Steps

A format.v

module main
fn main() {
        a := 31.2400e+200
        println('31.2400e+200 8.0g[${a:8.0g}]')
        println('31.2400e+200 8.1g[${a:8.1g}]')
        println('31.2400e+200 8.2g[${a:8.2g}]')
        println('31.2400e+200 8.3g[${a:8.3g}]')
        println('31.2400e+200 8.4g[${a:8.4g}]')
}

result is :

31.2400e+200 8.0g[        ]
31.2400e+200 8.1g[3.1e+201]
31.2400e+200 8.2g[3.12e+201]
31.2400e+200 8.3g[3.124e+201]
31.2400e+200 8.4g[3.124e+201]

A format.c

#include <stdio.h>
void main() {
        double c = 31.2400e+200;
        printf("31.2400e+200 8.0g[%8.0g]\n",c);
        printf("31.2400e+200 8.1g[%8.1g]\n",c);
        printf("31.2400e+200 8.2g[%8.2g]\n",c);
        printf("31.2400e+200 8.3g[%8.3g]\n",c);
        printf("31.2400e+200 8.4g[%8.4g]\n",c);
}

result is :

31.2400e+200 8.0g[  3e+201]
31.2400e+200 8.1g[  3e+201]
31.2400e+200 8.2g[3.1e+201]
31.2400e+200 8.3g[3.12e+201]
31.2400e+200 8.4g[3.124e+201]

Expected Behavior

V version will generate same result to it's C version

Current Behavior

They are different.

Possible Solution

format process has some bug?

Additional Information/Context

No response

V version

V full version: V 0.4.8 7b8e059.0390c07

Environment details (OS name and version, etc.)

V full version: V 0.4.8 7b8e059.0390c07
OS: linux, Ubuntu 24.04.1 LTS
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz

getwd: /home/mars/v/format
vexe: /media/HD/github/kbkpbot/v/v
vexe mtime: 2024-10-04 14:33:40

vroot: OK, value: /media/HD/github/kbkpbot/v
VMODULES: OK, value: /home/mars/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.0
Git vroot status: 0.4.8-42-g0a997d90 (3 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@kbkpbot kbkpbot added the Bug This tag is applied to issues which reports bugs. label Oct 6, 2024
@kbkpbot
Copy link
Contributor Author

kbkpbot commented Oct 6, 2024

ss.v

fn main() {
        a := 1234.5600e+100

        println('1234.5600e+100 8.3g[${a:8.3g}]')
}

create a wrong result:

1234.5600e+100 8.3g[0.1235e+104]

This should be :

1234.5600e+100 8.3g[1.23e+103]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant