All files / src/decoders number.ts

100% Statements 18/18
100% Branches 3/3
100% Functions 5/5
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44      1x       1x       1x       121x 121x 121x 121x       25x   25x   25x   23x 23x     1x 1x     1x 1x     25x 25x    
import { DecodeContext } from '../decode';
 
export function decodeNaN(): number {
	return NaN;
}
 
export function decodePositiveInfinity(): number {
	return Number.POSITIVE_INFINITY;
}
 
export function decodeNegativeInfinity(): number {
	return Number.NEGATIVE_INFINITY;
}
 
export function decodeInt(context: DecodeContext): number {
	const { reader, values } = context;
	const int = reader.readIntVar();
	values.push(int);
	return int;
}
 
export function decodeFloat(context: DecodeContext): number {
	const { reader, values, floatQuality } = context;
 
	let value = 0;
 
	switch (floatQuality) {
		case 'double':
			value = reader.readFloat64();
			break;
 
		case 'single':
			value = reader.readFloat32();
			break;
 
		default:
			value = reader.readUintVar() / floatQuality;
			break;
	}
 
	values.push(value);
	return value;
}