Skip to content
Open

nan #89

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@
],
"license": "MIT",
"dependencies": {
"@cto.af/wtf8": "0.0.3"
"@cto.af/wtf8": "0.0.4"
},
"devDependencies": {
"@cto.af/eslint-config": "6.0.9",
"@eslint/markdown": "6.6.0",
"@cto.af/eslint-config": "6.0.12",
"@eslint/markdown": "7.1.0",
"c8": "10.1.3",
"cbor-edn": "0.2.2",
"eslint": "9.29.0",
"eslint-plugin-jsdoc": "51.2.3",
"package-extract": "3.1.0",
"eslint": "9.32.0",
"eslint-plugin-jsdoc": "52.0.2",
"package-extract": "3.1.3",
"rimraf": "^6.0.1",
"tsup": "8.5.0",
"typedoc": "0.28.5",
"typescript-eslint": "8.35.0"
"typedoc": "0.28.9",
"typescript-eslint": "8.38.0"
},
"pnpm": {
"overrides": {
Expand All @@ -89,7 +89,7 @@
"esbuild"
]
},
"packageManager": "pnpm@10.12.3",
"packageManager": "pnpm@10.14.0",
"engines": {
"node": ">=20"
}
Expand Down
901 changes: 433 additions & 468 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
RequiredEncodeOptions,
} from './options.js';
import {type KeyValueEncoded, sortCoreDeterministic} from './sorts.js';
import {NAN, checkSubnormal} from './float.js';
import {box, getEncoded, saveEncoded} from './box.js';
import {defaultEncodeOptions, encode} from './encoder.js';
import {stringToHex, u8concat, u8toHex} from './utils.js';
import {DecodeStream} from './decodeStream.js';
import {Simple} from './simple.js';
import {Tag} from './tag.js';
import {checkSubnormal} from './float.js';

const LENGTH_FOR_AI = new Map([
[NUMBYTES.ZERO, 1],
Expand Down Expand Up @@ -56,6 +56,7 @@ export class CBORcontainer {
diagnosticSizes: DiagnosticSizes.PREFERRED,
convertUnsafeIntsToFloat: false,
createObject,
keepNanPayloads: false,
pretty: false,
preferMap: false,
rejectLargeNegatives: false,
Expand Down Expand Up @@ -204,16 +205,30 @@ export class CBORcontainer {
}
case MT.SIMPLE_FLOAT:
if (ai > NUMBYTES.ONE) {
if (typeof value === 'symbol') {
return value; // BREAK
}
if (opts.rejectFloats) {
throw new Error(`Decoding unwanted floating point number: ${value}`);
}
if (opts.rejectNegativeZero && Object.is(value, -0)) {
throw new Error('Decoding negative zero');
}
if (opts.rejectLongLoundNaN && isNaN(value as number)) {
if (isNaN(value as number)) {
const buf = stream.toHere(offset);
if (buf.length !== 3 || buf[1] !== 0x7e || buf[2] !== 0) {
throw new Error(`Invalid NaN encoding: "${u8toHex(buf)}"`);
const val = new NAN(buf);
if (opts.rejectLongLoundNaN) {
// If not quiet, there will be a payload.
if (val.payload || (buf.length > 3)) {
throw new Error(`Invalid NaN encoding: "${u8toHex(buf)}"`);
}
} else if (opts.keepNanPayloads) {
if (val.payload) {
if (opts.rejectLongFloats && !val.isShortestEncoding) {
throw new Error(`NaN should have been encoded shorter: ${value}`);
}
return val;
}
}
}
if (opts.rejectSubnormals) {
Expand Down
Loading
Loading