CodeSampleX

サンプル

@xtuc/ieee754 1.2.0: read and write IEEE754 floating point numbers

検証済みサンプル — npm @xtuc/ieee754 1.2.0: read and write IEEE754 floating point numbers. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:49697b6e94b60f72f906475d8e1b9e8c0222e84d506ccf44a343cbf5f29b7c2a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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
ゴール
read and write IEEE754 floating point numbers
パッケージ
シンボル
  • @xtuc/ieee754.read
  • @xtuc/ieee754.write
作成日
2026-08-27T23:36:10Z

コントラクト

  1. exports read and write functions from @xtuc/ieee754 module
  2. writes and reads 32-bit single precision floats in little-endian format with mLen=23 and nBytes=4
  3. writes and reads 32-bit single precision floats in big-endian format with mLen=23 and nBytes=4
  4. writes and reads 64-bit double precision floats in little-endian format with mLen=52 and nBytes=8
  5. writes and reads 64-bit double precision floats in big-endian format with mLen=52 and nBytes=8
  6. encodes and decodes special IEEE754 values including positive and negative zero, infinity, and NaN

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
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: read and write IEEE754 floating point numbers
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40xtuc/ieee754@1.2.0
Demonstrate these symbols/APIs:
  - @xtuc/ieee754.read
  - @xtuc/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.
csx.json
{"case":{"caseId":"case:sha256:9526910d2b6748024ea54c6ed943ab95408d1b668a1b02e3f2d2361126c7d0ec","contract":["exports read and write functions from @xtuc/ieee754 module","writes and reads 32-bit single precision floats in little-endian format with mLen=23 and nBytes=4","writes and reads 32-bit single precision floats in big-endian format with mLen=23 and nBytes=4","writes and reads 64-bit double precision floats in little-endian format with mLen=52 and nBytes=8","writes and reads 64-bit double precision floats in big-endian format with mLen=52 and nBytes=8","encodes and decodes special IEEE754 values including positive and negative zero, infinity, and NaN"],"goal":"read and write IEEE754 floating point numbers","kind":"HOW","packages":["pkg:npm/%40xtuc/ieee754@1.2.0"],"schemaVersion":1,"symbols":["@xtuc/ieee754.read","@xtuc/ieee754.write"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40xtuc/ieee754@1.2.0"],"schemaVersion":1,"subject":"pkg:npm/%40xtuc/ieee754@1.2.0","symbols":["@xtuc/ieee754.read","@xtuc/ieee754.write"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-xtuc-ieee754-read-write",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-xtuc-ieee754-read-write",
      "version": "1.0.0",
      "license": "MIT-0",
      "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"
    }
  }
}
package.json
{
  "name": "sample-xtuc-ieee754-read-write",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@xtuc/ieee754": "1.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "read and write IEEE754 floating point numbers",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40xtuc/ieee754@1.2.0"
  ],
  "symbols": [
    "@xtuc/ieee754.read",
    "@xtuc/ieee754.write"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { read, write } from '@xtuc/ieee754';
import * as ieee754Module from '@xtuc/ieee754';

// 1. Verify module exports
assert.equal(typeof read, 'function', 'read must be a function');
assert.equal(typeof write, 'function', 'write must be a function');
assert.equal(typeof ieee754Module.read, 'function', 'read must be exported');
assert.equal(typeof ieee754Module.write, 'function', 'write must be exported');

// 2. 32-bit float Little Endian (mLen=23, nBytes=4)
{
  const buf = Buffer.alloc(4);
  const testVal = 42.5;
  write(buf, testVal, 0, true, 23, 4);
  const result = read(buf, 0, true, 23, 4);
  assert.equal(result, testVal, '32-bit float LE must round-trip correctly');
}

// 3. 32-bit float Big Endian (mLen=23, nBytes=4)
{
  const buf = Buffer.alloc(4);
  const testVal = -42.5;
  write(buf, testVal, 0, false, 23, 4);
  const result = read(buf, 0, false, 23, 4);
  assert.equal(result, testVal, '32-bit float BE must round-trip correctly');
}

// 4. 64-bit float Little Endian (mLen=52, nBytes=8)
{
  const buf = Buffer.alloc(8);
  const testVal = 3.141592653589793;
  write(buf, testVal, 0, true, 52, 8);
  const result = read(buf, 0, true, 52, 8);
  assert.equal(result, testVal, '64-bit float LE must round-trip correctly');
}

// 5. 64-bit float Big Endian (mLen=52, nBytes=8)
{
  const buf = Buffer.alloc(8);
  const testVal = -1234567.890123456;
  write(buf, testVal, 0, false, 52, 8);
  const result = read(buf, 0, false, 52, 8);
  assert.equal(result, testVal, '64-bit float BE must round-trip correctly');
}

// 6. Special IEEE 754 values (+0, -0, +Infinity, -Infinity, NaN)
{
  const buf = Buffer.alloc(40);
  
  // +0
  write(buf, 0, 0, true, 52, 8);
  assert.equal(Object.is(read(buf, 0, true, 52, 8), +0), true, '+0 must be preserved');

  // -0
  write(buf, -0, 8, true, 52, 8);
  assert.equal(Object.is(read(buf, 8, true, 52, 8), -0), true, '-0 must be preserved');

  // +Infinity
  write(buf, Infinity, 16, true, 52, 8);
  assert.equal(read(buf, 16, true, 52, 8), Infinity, '+Infinity must be preserved');

  // -Infinity
  write(buf, -Infinity, 24, true, 52, 8);
  assert.equal(read(buf, 24, true, 52, 8), -Infinity, '-Infinity must be preserved');

  // NaN
  write(buf, NaN, 32, true, 52, 8);
  assert.equal(Number.isNaN(read(buf, 32, true, 52, 8)), true, 'NaN must be preserved');
}

console.log('Contract passed: read and write in pkg:npm/@xtuc/ieee754@1.2.0 successfully verified');

オリジンシーダー

匿名