Skip to content

assert x == y when x and y are f32 values, failed to print different values, for x := math.f32_from_bits(1055100473) and y := math.f32_from_bits(1055100475) #25141

Description

@spytheman
V version: V 0.4.11 b502d52, press to see full `v doctor` output
V full version V 0.4.11 9f91064.b502d52
OS linux, Ubuntu 20.04.6 LTS
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz
Memory 1.21GB/15.05GB
V executable /home/delian/v/v
V last modified time 2025-08-20 05:32:20
V home dir OK, value: /home/delian/v
VMODULES OK, value: /home/delian/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/delian/v
env VFLAGS "-no-parallel"
Git version git version 2.50.0
V git status weekly.2025.34-2-gb502d522
.git/config present true
cc version cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
gcc version gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
clang version N/A
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.31-0ubuntu9.18) 2.31

What did you do?
./v -g -o vdbg cmd/v && ./vdbg m.v && m

import math

found := math.f32_from_bits(1055100473)
expected := math.f32_from_bits(1055100475)
assert math.tolerance(found, expected, 0.0000002) // passes
// assert math.tolerance(found, expected, 0.0000001) // fails
assert found == expected
// The above line produces a print of:
// m.v:7: FAIL: fn main.main: assert found == expected
//    left value: found = 0.4444445
//   right value: expected = 0.4444445
// ... i.e. the printed values seem the same, which makes it very difficult
// ... to understand the diff.

What did you see?

m.v:7: FAIL: fn main.main: assert found == expected
   left value: found = 0.4444445
  right value: expected = 0.4444445
V panic: Assertion failed...
v hash: b502d52
/tmp/v_1000/m.01K33CGJ1PK9J18V4PQ7JM29KA.tmp.c:3552: at _v_panic: Backtrace
/tmp/v_1000/m.01K33CGJ1PK9J18V4PQ7JM29KA.tmp.c:5974: by main__main
/tmp/v_1000/m.01K33CGJ1PK9J18V4PQ7JM29KA.tmp.c:6001: by main

What did you expect to see?

a failed assertion, where the printed values are visibly different from each other, not the same ones

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.

Metadata

Metadata

Assignees

Labels

Assert statementsBugs related to `assert` statementsBugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.strconv module

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions