示例
ieee754 1.2.1: write
已验证示例 — npm ieee754 1.2.1: write. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: write encodes 32-bit floating point numbers in little-endian and…
sha256:b4cb1c5bf65e4101595678372b594a70d4f4d8b5a6dee6494bf72f40c94815f4
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-06 |
案例
HOW- 目标
- verify ieee754.write in pkg:npm/ieee754@1.2.1
- 符号
-
- ieee754.write
- 环境
- node 22.23.2
- 创建时间
- 2026-09-06T12:19:59Z
契约
- write encodes 32-bit floating point numbers in little-endian and big-endian byte order
- write encodes 64-bit double-precision floating point numbers matching IEEE 754 representations
- write encodes special values including positive zero, negative zero, infinity, and NaN
- write writes values into target buffers at arbitrary valid offsets without disturbing adjacent bytes
- write operates directly on standard Uint8Array and Node.js Buffer instances
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
源代码
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: verify ieee754.write in pkg:npm/ieee754@1.2.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ieee754@1.2.1
Demonstrate these symbols/APIs:
- ieee754.write
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:98e1513d4ac0764f782b7011021f853fe3d86e9d682da70b8c7fbf0b4bb3dfdb","contract":["write encodes 32-bit floating point numbers in little-endian and big-endian byte order","write encodes 64-bit double-precision floating point numbers matching IEEE 754 representations","write encodes special values including positive zero, negative zero, infinity, and NaN","write writes values into target buffers at arbitrary valid offsets without disturbing adjacent bytes","write operates directly on standard Uint8Array and Node.js Buffer instances"],"goal":"verify ieee754.write in pkg:npm/ieee754@1.2.1","kind":"HOW","packages":["pkg:npm/ieee754@1.2.1"],"schemaVersion":1,"symbols":["ieee754.write"]},"contractCommand":["node","test/contract.js"],"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/ieee754@1.2.1"],"schemaVersion":1,"subject":"pkg:npm/ieee754@1.2.1","symbols":["ieee754.write"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-ieee754-write",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ieee754-write",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ieee754": "1.2.1"
}
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "BSD-3-Clause"
}
}
}
{
"name": "sample-ieee754-write",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for ieee754.write",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"ieee754": "1.2.1"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify ieee754.write in pkg:npm/ieee754@1.2.1",
"kind": "HOW",
"packages": [
"pkg:npm/ieee754@1.2.1"
],
"symbols": [
"ieee754.write"
]
}
const ieee754 = require('ieee754');
/**
* Writes a 32-bit single-precision floating point number into a buffer.
* @param {Uint8Array|Buffer} buffer Target buffer
* @param {number} value Value to write
* @param {number} [offset=0] Byte offset
* @param {boolean} [isLE=true] True for little-endian, false for big-endian
*/
function writeFloat32(buffer, value, offset = 0, isLE = true) {
ieee754.write(buffer, value, offset, isLE, 23, 4);
}
/**
* Writes a 64-bit double-precision floating point number into a buffer.
* @param {Uint8Array|Buffer} buffer Target buffer
* @param {number} value Value to write
* @param {number} [offset=0] Byte offset
* @param {boolean} [isLE=true] True for little-endian, false for big-endian
*/
function writeFloat64(buffer, value, offset = 0, isLE = true) {
ieee754.write(buffer, value, offset, isLE, 52, 8);
}
/**
* Allocates a new buffer and encodes a floating point number into it.
* @param {number} value Floating point number
* @param {'single'|'double'} [precision='double'] Precision mode
* @param {boolean} [isLE=true] Endianness
* @returns {Buffer} Encoded buffer
*/
function encodeFloatingPoint(value, precision = 'double', isLE = true) {
const isSingle = precision === 'single';
const size = isSingle ? 4 : 8;
const mLen = isSingle ? 23 : 52;
const buffer = Buffer.alloc(size);
ieee754.write(buffer, value, 0, isLE, mLen, size);
return buffer;
}
module.exports = {
ieee754,
write: ieee754.write,
read: ieee754.read,
writeFloat32,
writeFloat64,
encodeFloatingPoint,
};
const assert = require('node:assert');
const {
ieee754,
write,
read,
writeFloat32,
writeFloat64,
encodeFloatingPoint,
} = require('../src/index.js');
// 1. write encodes 32-bit floating point numbers in little-endian and big-endian byte order
{
const bufLE = Buffer.alloc(4);
const bufBE = Buffer.alloc(4);
write(bufLE, 42.5, 0, true, 23, 4);
write(bufBE, 42.5, 0, false, 23, 4);
const expectedBE = Buffer.from([0x42, 0x2a, 0x00, 0x00]);
const expectedLE = Buffer.from([0x00, 0x00, 0x2a, 0x42]);
assert(bufLE.equals(expectedLE), '32-bit LE mismatch');
assert(bufBE.equals(expectedBE), '32-bit BE mismatch');
const refLE = Buffer.alloc(4);
refLE.writeFloatLE(42.5, 0);
assert(bufLE.equals(refLE), '32-bit LE ref mismatch');
const helperBuf = Buffer.alloc(4);
writeFloat32(helperBuf, 42.5, 0, true);
assert(helperBuf.equals(expectedLE), 'writeFloat32 LE mismatch');
}
// 2. write encodes 64-bit double-precision floating point numbers matching IEEE 754 representations
{
const testValues = [1.0, -0.5, Math.PI, 12345.6789];
for (const v of testValues) {
const bufLE = Buffer.alloc(8);
const bufBE = Buffer.alloc(8);
write(bufLE, v, 0, true, 52, 8);
write(bufBE, v, 0, false, 52, 8);
const refLE = Buffer.alloc(8);
const refBE = Buffer.alloc(8);
refLE.writeDoubleLE(v, 0);
refBE.writeDoubleBE(v, 0);
assert(bufLE.equals(refLE), `64-bit LE ref mismatch for ${v}`);
assert(bufBE.equals(refBE), `64-bit BE ref mismatch for ${v}`);
const encoded = encodeFloatingPoint(v, 'double', true);
assert(encoded.equals(refLE), `encodeFloatingPoint mismatch for ${v}`);
}
}
// 3. write encodes special values including positive zero, negative zero, infinity, and NaN
{
const posZero = Buffer.alloc(8);
const negZero = Buffer.alloc(8);
write(posZero, 0, 0, false, 52, 8);
write(negZero, -0, 0, false, 52, 8);
assert.strictEqual(posZero[0] & 0x80, 0x00, '+0 must not have sign bit set');
assert.strictEqual(negZero[0] & 0x80, 0x80, '-0 must have sign bit set');
const infBuf = Buffer.alloc(8);
const negInfBuf = Buffer.alloc(8);
write(infBuf, Infinity, 0, false, 52, 8);
write(negInfBuf, -Infinity, 0, false, 52, 8);
assert.strictEqual(read(infBuf, 0, false, 52, 8), Infinity);
assert.strictEqual(read(negInfBuf, 0, false, 52, 8), -Infinity);
const nanBuf = Buffer.alloc(8);
write(nanBuf, NaN, 0, true, 52, 8);
assert(Number.isNaN(read(nanBuf, 0, true, 52, 8)), 'NaN must decode to NaN');
}
// 4. write writes values into target buffers at arbitrary valid offsets without disturbing adjacent bytes
{
const sentinel = 0xee;
const buf = Buffer.alloc(16, sentinel);
write(buf, 42.5, 2, true, 23, 4);
assert.strictEqual(buf[0], sentinel);
assert.strictEqual(buf[1], sentinel);
assert.strictEqual(buf[6], sentinel);
assert.strictEqual(buf[15], sentinel);
const decoded = read(buf, 2, true, 23, 4);
assert.strictEqual(decoded, 42.5);
}
// 5. write operates directly on standard Uint8Array and Node.js Buffer instances
{
const uint8 = new Uint8Array(8);
write(uint8, 987.654, 0, true, 52, 8);
const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
assert.strictEqual(view.getFloat64(0, true), 987.654);
}
console.log('All contract assertions passed successfully.');
原始种子者
匿名