Пример
@webassemblyjs/ieee754 1.13.2: encode and decode 32-bit and 64-bit floating point numbers using IEEE 754
Проверенный пример — npm @webassemblyjs/ieee754 1.13.2: encode and decode 32-bit and 64-bit floating point numbers using IEEE 754. Контракт выполнен на node…
sha256:b2e073cfd4e7e84514f60efb8b26d85178ca1b775de59f90359b6411384d7438
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-27 |
Кейс
HOW- Цель
- encode and decode 32-bit and 64-bit floating point numbers using IEEE 754
- Символы
-
- decodeF32
- decodeF64
- encodeF32
- encodeF64
- Окружение
- node 22.23.2
- Создан
- 2026-08-27T23:25:51Z
Контракт
- assert encodeF32 returns a 4-byte little-endian array and decodeF32 round-trips single-precision floats
- assert encodeF32 and decodeF32 handle special float values including Infinity, -Infinity, and NaN
- assert encodeF64 returns an 8-byte little-endian array and decodeF64 round-trips double-precision floats
- assert encodeF64 and decodeF64 handle special double values including Infinity, -Infinity, and NaN
- assert decodeF32 and decodeF64 accept Uint8Array byte buffers as input
Файлы
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Исходный код
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: encode and decode 32-bit and 64-bit floating point numbers using IEEE 754
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40webassemblyjs/ieee754@1.13.2
Demonstrate these symbols/APIs:
- decodeF32
- decodeF64
- encodeF32
- encodeF64
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:d2447a0864404d1084510a613aff8e1b390eabc487921053a62b4a6c8d925d5a","contract":["assert encodeF32 returns a 4-byte little-endian array and decodeF32 round-trips single-precision floats","assert encodeF32 and decodeF32 handle special float values including Infinity, -Infinity, and NaN","assert encodeF64 returns an 8-byte little-endian array and decodeF64 round-trips double-precision floats","assert encodeF64 and decodeF64 handle special double values including Infinity, -Infinity, and NaN","assert decodeF32 and decodeF64 accept Uint8Array byte buffers as input"],"goal":"encode and decode 32-bit and 64-bit floating point numbers using IEEE 754","kind":"HOW","packages":["pkg:npm/%40webassemblyjs/ieee754@1.13.2"],"schemaVersion":1,"symbols":["decodeF32","decodeF64","encodeF32","encodeF64"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40webassemblyjs/ieee754@1.13.2"],"schemaVersion":1,"subject":"pkg:npm/%40webassemblyjs/ieee754@1.13.2","symbols":["decodeF32","decodeF64","encodeF32","encodeF64"],"verifierAdapter":"node-typescript@1"}
const {
encodeF32,
decodeF32,
encodeF64,
decodeF64,
NUMBER_OF_BYTE_F32,
NUMBER_OF_BYTE_F64,
SINGLE_PRECISION_MANTISSA,
DOUBLE_PRECISION_MANTISSA,
} = require('@webassemblyjs/ieee754');
/**
* Encodes a 32-bit single-precision float into an array of 4 little-endian bytes.
* @param {number} value
* @returns {number[]}
*/
function encodeFloat32(value) {
return encodeF32(value);
}
/**
* Decodes an array or Uint8Array of 4 little-endian bytes into a 32-bit float.
* @param {number[] | Uint8Array} bytes
* @returns {number}
*/
function decodeFloat32(bytes) {
return decodeF32(bytes);
}
/**
* Encodes a 64-bit double-precision float into an array of 8 little-endian bytes.
* @param {number} value
* @returns {number[]}
*/
function encodeFloat64(value) {
return encodeF64(value);
}
/**
* Decodes an array or Uint8Array of 8 little-endian bytes into a 64-bit float.
* @param {number[] | Uint8Array} bytes
* @returns {number}
*/
function decodeFloat64(bytes) {
return decodeF64(bytes);
}
module.exports = {
encodeFloat32,
decodeFloat32,
encodeFloat64,
decodeFloat64,
encodeF32,
decodeF32,
encodeF64,
decodeF64,
NUMBER_OF_BYTE_F32,
NUMBER_OF_BYTE_F64,
SINGLE_PRECISION_MANTISSA,
DOUBLE_PRECISION_MANTISSA,
};
{
"name": "sample-webassemblyjs-ieee754",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-webassemblyjs-ieee754",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@webassemblyjs/ieee754": "1.13.2"
}
},
"node_modules/@webassemblyjs/ieee754": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.13.2.tgz",
"integrity": "sha512-4LtOzh58S/5lX4ITKxnAK2USuNEvpdVV9AlgGQb8rJDHaLeHciwG4zlGr0j/SNWlr7x3vO1lDEsuePvtcDNCkw==",
"license": "MIT",
"dependencies": {
"@xtuc/ieee754": "^1.2.0"
}
},
"node_modules/@xtuc/ieee754": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz",
"integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==",
"license": "BSD-3-Clause"
}
}
}
{
"name": "sample-webassemblyjs-ieee754",
"version": "1.0.0",
"description": "Clean-room sample verifying @webassemblyjs/ieee754 float encoding and decoding",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"@webassemblyjs/ieee754": "1.13.2"
}
}
{
"schemaVersion": 1,
"goal": "encode and decode 32-bit and 64-bit floating point numbers using IEEE 754",
"kind": "HOW",
"packages": [
"pkg:npm/%40webassemblyjs/ieee754@1.13.2"
],
"symbols": [
"decodeF32",
"decodeF64",
"encodeF32",
"encodeF64"
]
}
import assert from 'node:assert';
import {
encodeF32,
decodeF32,
encodeF64,
decodeF64,
} from '@webassemblyjs/ieee754';
import {
encodeFloat32,
decodeFloat32,
encodeFloat64,
decodeFloat64,
} from '../index.js';
// 1. encodeF32 and decodeF32: standard values
const f32OneBytes = encodeF32(1.0);
assert(Array.isArray(f32OneBytes), 'encodeF32 must return an Array');
assert.strictEqual(f32OneBytes.length, 4, 'encodeF32 must return 4 bytes for single-precision float');
assert.deepStrictEqual(f32OneBytes, [0, 0, 128, 63], 'encodeF32(1.0) must produce [0x00, 0x00, 0x80, 0x3F]');
assert.strictEqual(decodeF32(f32OneBytes), 1.0, 'decodeF32 must round-trip 1.0 correctly');
const f32NegBytes = encodeFloat32(-1.0);
assert.deepStrictEqual(f32NegBytes, [0, 0, 128, 191], 'encodeF32(-1.0) must produce [0x00, 0x00, 0x80, 0xBF]');
assert.strictEqual(decodeFloat32(f32NegBytes), -1.0, 'decodeF32 must decode -1.0 correctly');
const f32ZeroBytes = encodeF32(0.0);
assert.deepStrictEqual(f32ZeroBytes, [0, 0, 0, 0], 'encodeF32(0.0) must produce [0, 0, 0, 0]');
assert.strictEqual(decodeF32(f32ZeroBytes), 0.0, 'decodeF32 must decode 0.0 correctly');
// 2. encodeF32 and decodeF32: special values (Infinity, -Infinity, NaN)
const f32InfBytes = encodeF32(Infinity);
assert.deepStrictEqual(f32InfBytes, [0, 0, 128, 127], 'encodeF32(Infinity) must produce [0, 0, 128, 127]');
assert.strictEqual(decodeF32(f32InfBytes), Infinity, 'decodeF32 must decode Infinity correctly');
const f32NegInfBytes = encodeF32(-Infinity);
assert.deepStrictEqual(f32NegInfBytes, [0, 0, 128, 255], 'encodeF32(-Infinity) must produce [0, 0, 128, 255]');
assert.strictEqual(decodeF32(f32NegInfBytes), -Infinity, 'decodeF32 must decode -Infinity correctly');
const f32NaNBytes = encodeF32(NaN);
assert(Number.isNaN(decodeF32(f32NaNBytes)), 'decodeF32(encodeF32(NaN)) must return NaN');
// 3. encodeF64 and decodeF64: standard values
const f64OneBytes = encodeF64(1.0);
assert(Array.isArray(f64OneBytes), 'encodeF64 must return an Array');
assert.strictEqual(f64OneBytes.length, 8, 'encodeF64 must return 8 bytes for double-precision float');
assert.deepStrictEqual(f64OneBytes, [0, 0, 0, 0, 0, 0, 240, 63], 'encodeF64(1.0) must produce 8-byte little-endian IEEE 754 representation');
assert.strictEqual(decodeF64(f64OneBytes), 1.0, 'decodeF64 must round-trip 1.0 correctly');
const f64NegBytes = encodeFloat64(-1.0);
assert.deepStrictEqual(f64NegBytes, [0, 0, 0, 0, 0, 0, 240, 191], 'encodeF64(-1.0) must produce [0, 0, 0, 0, 0, 0, 240, 191]');
assert.strictEqual(decodeFloat64(f64NegBytes), -1.0, 'decodeFloat64 must decode -1.0 correctly');
const f64PiBytes = encodeF64(Math.PI);
assert.strictEqual(decodeF64(f64PiBytes), Math.PI, 'decodeF64 must round-trip Math.PI double-precision float accurately');
// 4. encodeF64 and decodeF64: special values (Infinity, -Infinity, NaN)
const f64InfBytes = encodeF64(Infinity);
assert.deepStrictEqual(f64InfBytes, [0, 0, 0, 0, 0, 0, 240, 127], 'encodeF64(Infinity) must produce [0, 0, 0, 0, 0, 0, 240, 127]');
assert.strictEqual(decodeF64(f64InfBytes), Infinity, 'decodeF64 must decode Infinity correctly');
const f64NegInfBytes = encodeF64(-Infinity);
assert.deepStrictEqual(f64NegInfBytes, [0, 0, 0, 0, 0, 0, 240, 255], 'encodeF64(-Infinity) must produce [0, 0, 0, 0, 0, 0, 240, 255]');
assert.strictEqual(decodeF64(f64NegInfBytes), -Infinity, 'decodeF64 must decode -Infinity correctly');
const f64NaNBytes = encodeF64(NaN);
assert(Number.isNaN(decodeF64(f64NaNBytes)), 'decodeF64(encodeF64(NaN)) must return NaN');
// 5. decodeF32 and decodeF64 accept Uint8Array byte buffers as input
const uint8F32 = new Uint8Array([0, 0, 128, 63]);
assert.strictEqual(decodeF32(uint8F32), 1.0, 'decodeF32 must accept Uint8Array input');
const uint8F64 = new Uint8Array([0, 0, 0, 0, 0, 0, 240, 63]);
assert.strictEqual(decodeF64(uint8F64), 1.0, 'decodeF64 must accept Uint8Array input');
console.log('All contract assertions passed.');
Исходный сидер
аноним