diff --git a/README.md b/README.md index c30de111..c6f6f7b6 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ bun add @petamoriken/float16 import { Float16Array, isFloat16Array, isTypedArray, getFloat16, setFloat16, - hfround, + f16round, } from "@petamoriken/float16"; ``` @@ -72,7 +72,7 @@ import { const { Float16Array, isFloat16Array, isTypedArray, getFloat16, setFloat16, - hfround, + f16round, } = require("@petamoriken/float16"); ``` @@ -85,7 +85,7 @@ service. import { Float16Array, isFloat16Array, isTypedArray, getFloat16, setFloat16, - hfround, + f16round, } from "https://deno.land/x/float16/mod.ts"; ``` @@ -100,7 +100,7 @@ from your Web server with the JavaScript `Content-Type` HTTP header. import { Float16Array, isFloat16Array, isTypedArray, getFloat16, setFloat16, - hfround, + f16round, } from "DEST/TO/float16.mjs"; ``` @@ -112,7 +112,7 @@ from your Web server with the JavaScript `Content-Type` HTTP header. const { Float16Array, isFloat16Array, isTypedArray, getFloat16, setFloat16, - hfround, + f16round, } = float16; ``` @@ -126,7 +126,7 @@ from your Web server with the JavaScript `Content-Type` HTTP header. import { Float16Array, isFloat16Array, isTypedArray, getFloat16, setFloat16, - hfround, + f16round, } from "https://cdn.jsdelivr.net/npm/@petamoriken/float16/+esm"; ``` @@ -138,7 +138,7 @@ from your Web server with the JavaScript `Content-Type` HTTP header. const { Float16Array, isFloat16Array, isTypedArray, getFloat16, setFloat16, - hfround, + f16round, } = float16; ``` @@ -250,19 +250,19 @@ view.setFloat16(0, Math.PI, true); view.getFloat16(0, true); // 3.140625 ``` -### `hfround` +### `f16round` (`hfround`) -`hfround` is similar to `Math.fround` +`f16round` is similar to `Math.fround` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)). This function returns nearest half-precision float representation of a number. ```ts -declare function hfround(x: number): number; +declare function f16round(x: number): number; ``` ```js Math.fround(1.337); // 1.3370000123977661 -hfround(1.337); // 1.3369140625 +f16round(1.337); // 1.3369140625 ``` ## `Float16Array` limitations (edge cases) diff --git a/index.d.ts b/index.d.ts index 7885948e..7e79bc17 100644 --- a/index.d.ts +++ b/index.d.ts @@ -488,4 +488,11 @@ export declare function setFloat16( * Returns the nearest half-precision float representation of a number. * @param x A numeric expression. */ +export declare function f16round(x: number): number; + +/** + * Returns the nearest half-precision float representation of a number. + * @alias f16round + * @param x A numeric expression. + */ export declare function hfround(x: number): number; diff --git a/package.json b/package.json index deb34f86..5278b962 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "DataView", "getFloat16", "setFloat16", - "hfround", + "f16round", "ponyfill", "shim" ], diff --git a/src/hfround.mjs b/src/f16round.mjs similarity index 93% rename from src/hfround.mjs rename to src/f16round.mjs index ce65e037..ee24fbc8 100644 --- a/src/hfround.mjs +++ b/src/f16round.mjs @@ -7,7 +7,7 @@ import { NumberIsFinite } from "./_util/primordials.mjs"; * @param {number} x * @returns {number} */ -export function hfround(x) { +export function f16round(x) { const number = +x; // for optimization diff --git a/src/index.mjs b/src/index.mjs index aeac4507..978967aa 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -3,4 +3,4 @@ export { Float16Array, isFloat16Array } from "./Float16Array.mjs"; export { isTypedArray } from "./isTypedArray.mjs"; export { getFloat16, setFloat16 } from "./DataView.mjs"; -export { hfround } from "./hfround.mjs"; +export { f16round, f16round as hfround } from "./f16round.mjs"; diff --git a/test/browser/index.html b/test/browser/index.html index e8e725f4..83d695a3 100644 --- a/test/browser/index.html +++ b/test/browser/index.html @@ -28,7 +28,7 @@ - + - +