Giter Club home page Giter Club logo

Comments (9)

rossberg avatar rossberg commented on August 12, 2024

I'd suggest simply changing the implementation of assert_eq to use the stricter equality operator. Or is there any reason to ever use IEEE equality in the tests we want to write?

As for NaN tests, it is easy to express that in WASM itself, so I don't think we need to extend the assertion language just for that either.

from spec.

rossberg avatar rossberg commented on August 12, 2024

Btw, once your new float implementations land, = and <> on those types will automatically mean bitwise equality. So maybe it isn't even necessary to change anything here.

from spec.

sunfishcode avatar sunfishcode commented on August 12, 2024

You're right; there is no need for the looser equality in our tests. It just feels weird to me to give eq a subtly different meaning in this context than it has in wasm itself.

As for NaN tests, it seems like it will be quite inconvenient to express any-NaN tests in terms of assert_eq regardless of whether it's the strict or loose version. The strict one tests for a specific bit pattern when we want to accept many, and the loose version requires we name the value so that we can reference it twice and form x <> x. Or are you proposing we add NaN test functions inside the wasm modules themselves?

from spec.

sunfishcode avatar sunfishcode commented on August 12, 2024

BTW, you're right that = and <> now automatically do bitwise equality with my float implementations. How does that work, given that the types are abstract?

from spec.

sunfishcode avatar sunfishcode commented on August 12, 2024

Ah, I found a blog post which explains it.

from spec.

jfbastien avatar jfbastien commented on August 12, 2024

Agreed with what I think @rossberg-chromium is saying on NaNs: this should be done with a wasm function, e.g.: assert(is_nan(v)).

from spec.

rossberg avatar rossberg commented on August 12, 2024

BTW, you're right that = and <> now automatically do bitwise equality with
my float implementations. How does that work, given that the types are
abstract?

In Ocaml, equality is generic, and does the "right" thing depending on the
runtime type of the value.

That actually is quite a dubious semantics, given that IEEE defines a
completely broken notion of equality for floats (which is not even close to
being an equivalence relation). And as you observed, it also breaks
abstraction. I'd prefer what e.g. SML does, where IEEE equality is a
separate operator.

from spec.

sunfishcode avatar sunfishcode commented on August 12, 2024

Ok, I now have an implementation of assert_eq_bits and assert_nan, and tests that use them (test/float32.wasm and test/float64.wasm), in this branch:

https://github.com/WebAssembly/spec/tree/float-tests

It's still experimental (the final version may not actually want to weigh in at 17 MiB of tests, etc.) but I think this demonstrates some nice properties of assert_eq_bits and assert_nan:

  • It avoids using = and <> on Float32.t and Float64.t values. Even if OCaml makes this work, it breaks the encapsulation of abstract types.
  • It avoids ambiguity on the term eq with respect to floating point types.
  • Each assert line in the test files test/float32.wasm and test/float64.wasm makes exactly one call into the wasm module, and does nothing but check the result value.
  • It issues a human-readable error message when floating-point types are used for an integer assert, or integer types are used for a floating point assert.

What do people think?

from spec.

sunfishcode avatar sunfishcode commented on August 12, 2024

#81 implements this and is now merged.

from spec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.