Skip to content

Clarify the usage of 32 bit floating point type and consider using double #325

@huningxin

Description

@huningxin

This issue was raised during Chromium CL review. Thanks Jiewei @wacky6 for the valuable feedback!

The WebIDL 32 bit floating point type float is widely used by WebNN spec, such as for setting min and max value of clamp operator:

dictionary MLClampOptions {
  float minValue;
  float maxValue;
};

However, WebIDL spec has a warning of using float and the recommendation is to use double.

Unless there are specific reasons to use a 32 bit floating point type, specifications should use double rather than float, since the set of values that a double can represent more closely matches an ECMAScript Number.

According to that, Jiewei suggested that the spec should mention reason of using float (at least an informative note) and propose using double instead. The reasons include (pasted from the CL thread):

  • Don't see particular reasons for limiting this to fp32
  • What if (in the future) we have backends that can work with fp64? In this case fp32 becomes a limitation.
  • Would it be worthwhile specifying float point casting behavior in the spec? Say, if caller passes in a fp64 number (that is too large to represent in fp32/fp16), how should backend interpret this (cast to infinity, error, find closest value non-infinity, something else)?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions