# How to use maxSignificand method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

math.ts

Source:math.ts

`1/** @internal */2export const MIN_VALUE_32 = 2 ** -126 * 2 ** -23;3/** @internal */4export const MAX_VALUE_32 = 2 ** 127 * (1 + (2 ** 23 - 1) / 2 ** 23);5/** @internal */6export const EPSILON_32 = 2 ** -23;7/** @internal */8const INDEX_POSITIVE_INFINITY_32 = 2139095040; // floatToIndex(MAX_VALUE_32) + 1;9/** @internal */10const INDEX_NEGATIVE_INFINITY_32 = -2139095041; // floatToIndex(-MAX_VALUE_32) - 111export function safeFloatToIndex(f: number, label: string): IO<never, never, number> {12 const conversionTrick = "you can convert any double to a 32-bit float by using `new Float32Array([myDouble])[0]`";13 const errorMessage = "fc.floatNext constraints." + label + " must be a 32-bit float - " + conversionTrick;14 if (Number.isNaN(f) || (Number.isFinite(f) && (f < -MAX_VALUE_32 || f > MAX_VALUE_32))) {15 return IO.haltNow(new Error(errorMessage));16 }17 const index = floatToIndex(f);18 if (!Number.isInteger(index)) {19 return IO.haltNow(new Error(errorMessage));20 }21 return IO.succeedNow(index);22}23export function decomposeFloat(f: number): { exponent: number; significand: number } {24 // 1 => significand 0b1 - exponent 1 (will be preferred)25 // => significand 0b0.1 - exponent 226 const maxSignificand = 1 + (2 ** 23 - 1) / 2 ** 23;27 for (let exponent = -126; exponent !== 128; ++exponent) {28 const powExponent = 2 ** exponent;29 const maxForExponent = maxSignificand * powExponent;30 if (Math.abs(f) <= maxForExponent) {31 return { exponent, significand: f / powExponent };32 }33 }34 return { exponent: Number.NaN, significand: Number.NaN };35}36export function floatToIndex(f: number): number {37 if (f === Number.POSITIVE_INFINITY) {38 return INDEX_POSITIVE_INFINITY_32;39 }40 if (f === Number.NEGATIVE_INFINITY) {41 return INDEX_NEGATIVE_INFINITY_32;42 }43 const { exponent, significand } = decomposeFloat(f);44 if (Number.isNaN(exponent) || Number.isNaN(significand) || !Number.isInteger(significand * 0x800000)) {45 return Number.NaN;46 }47 if (f > 0 || (f === 0 && 1 / f === Number.POSITIVE_INFINITY)) {48 return indexInFloatFromDecomp(exponent, significand);49 } else {50 return -indexInFloatFromDecomp(exponent, -significand) - 1;51 }52}53/** @internal */54export function indexInFloatFromDecomp(exponent: number, significand: number) {55 // WARNING: significand >= 056 // By construct of significand in decomposeFloat,57 // significand is always max-ed.58 // The float close to zero are the only one having a significand <1, they also have an exponent of -126.59 // They are in range: [2**(-126) * 2**(-23), 2**(-126) * (2 - 2 ** 23)]60 // In other words there are 2**24 elements in that range if we include zero.61 // All other ranges (other exponents) have a length of 2**23 elements.62 if (exponent === -126) {63 return significand * 0x800000; // significand * 2**2364 }65 // Offset due to exp = -126 + Offset of previous exp (excl. -126) + Offset in current exp66 // 2**24 + (exponent - (-126) -1) * 2**23 + (significand - 1) * 2**2367 return (exponent + 127) * 0x800000 + (significand - 1) * 0x800000;68}69/**70 * Compute the 32-bit floating point number corresponding to the provided indexes71 *72 * @param n - index of the float73 *74 * @internal75 */76export function indexToFloat(index: number): number {77 if (index < 0) {78 return -indexToFloat(-index - 1);79 }80 if (index === INDEX_POSITIVE_INFINITY_32) {81 return Number.POSITIVE_INFINITY;82 }83 if (index < 0x1000000) {84 // The first 2**24 elements correspond to values having85 // exponent = -126 and significand = index * 2**(-23)86 return index * 2 ** -149;87 }88 const postIndex = index - 0x1000000;89 // Math.floor(postIndex / 0x800000) = Math.floor(postIndex / 2**23) = (postIndex >> 23)90 const exponent = -125 + (postIndex >> 23);91 // (postIndex % 0x800000) / 0x800000 = (postIndex & 0x7fffff) / 0x80000092 const significand = 1 + (postIndex & 0x7fffff) / 0x800000;93 return significand * 2 ** exponent;94}95/** @internal */96export type ArrayInt64 = { sign: 1 | -1; data: [number, number] };97/** @internal */98export const Zero64: ArrayInt64 = { sign: 1, data: [0, 0] };99/** @internal */100export const Unit64: ArrayInt64 = { sign: 1, data: [0, 1] };101/** @internal */102export function isZero64(a: ArrayInt64): boolean {103 return a.data[0] === 0 && a.data[1] === 0;104}105/** @internal */106export function isStrictlyNegative64(a: ArrayInt64): boolean {107 return a.sign === -1 && !isZero64(a);108}109/** @internal */110export function isStrictlyPositive64(a: ArrayInt64): boolean {111 return a.sign === 1 && !isZero64(a);112}113/** @internal */114export function isEqual64(a: ArrayInt64, b: ArrayInt64): boolean {115 if (a.data[0] === b.data[0] && a.data[1] === b.data[1]) {116 return a.sign === b.sign || (a.data[0] === 0 && a.data[1] === 0); // either the same or both zero117 }118 return false;119}120/** @internal */121function isStrictlySmaller64Internal(a: ArrayInt64["data"], b: ArrayInt64["data"]): boolean {122 return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1]);123}124/** @internal */125export function isStrictlySmaller64(a: ArrayInt64, b: ArrayInt64): boolean {126 if (a.sign === b.sign) {127 return a.sign === 1128 ? isStrictlySmaller64Internal(a.data, b.data) // a.sign = +1, b.sign = +1129 : isStrictlySmaller64Internal(b.data, a.data); // a.sign = -1, b.sign = -1130 }131 // a.sign = +1, b.sign = -1 is always false132 return a.sign === -1 && (!isZero64(a) || !isZero64(b)); // a.sign = -1, b.sign = +1133}134/** @internal */135export function clone64(a: ArrayInt64): ArrayInt64 {136 return { sign: a.sign, data: [a.data[0], a.data[1]] };137}138/** @internal */139function substract64DataInternal(a: ArrayInt64["data"], b: ArrayInt64["data"]): ArrayInt64["data"] {140 let reminderLow = 0;141 let low = a[1] - b[1];142 if (low < 0) {143 reminderLow = 1;144 low = low >>> 0;145 }146 return [a[0] - b[0] - reminderLow, low];147}148/**149 * Expects a >= b150 * @internal151 */152function substract64Internal(a: ArrayInt64, b: ArrayInt64): ArrayInt64 {153 if (a.sign === 1 && b.sign === -1) {154 // Operation is a simple sum of a + abs(b)155 const low = a.data[1] + b.data[1];156 const high = a.data[0] + b.data[0] + (low > 0xffffffff ? 1 : 0);157 return { sign: 1, data: [high >>> 0, low >>> 0] };158 }159 // a.sign === -1 with b.sign === 1 is impossible given: a - b >= 0, except for a = 0 and b = 0160 // Operation is a substraction161 return {162 sign: 1,163 data: a.sign === 1 ? substract64DataInternal(a.data, b.data) : substract64DataInternal(b.data, a.data),164 };165}166/**167 * Substract two ArrayInt64168 * @returns When result is zero always with sign=1169 * @internal170 */171export function substract64(arrayIntA: ArrayInt64, arrayIntB: ArrayInt64): ArrayInt64 {172 if (isStrictlySmaller64(arrayIntA, arrayIntB)) {173 const out = substract64Internal(arrayIntB, arrayIntA);174 out.sign = -1;175 return out;176 }177 return substract64Internal(arrayIntA, arrayIntB);178}179/**180 * Negative version of an ArrayInt64181 * @internal182 */183export function negative64(arrayIntA: ArrayInt64): ArrayInt64 {184 return {185 sign: -arrayIntA.sign as -1 | 1,186 data: [arrayIntA.data[0], arrayIntA.data[1]],187 };188}189/**190 * Add two ArrayInt64191 * @returns When result is zero always with sign=1192 * @internal193 */194export function add64(arrayIntA: ArrayInt64, arrayIntB: ArrayInt64): ArrayInt64 {195 if (isZero64(arrayIntB)) {196 if (isZero64(arrayIntA)) {197 return clone64(Zero64);198 }199 return clone64(arrayIntA);200 }201 return substract64(arrayIntA, negative64(arrayIntB));202}203/**204 * Halve an ArrayInt64205 * @internal206 */207export function halve64(a: ArrayInt64): ArrayInt64 {208 return {209 sign: a.sign,210 data: [Math.floor(a.data[0] / 2), (a.data[0] % 2 === 1 ? 0x80000000 : 0) + Math.floor(a.data[1] / 2)],211 };212}213/**214 * Apply log2 to an ArrayInt64 (preserve sign)215 * @internal216 */217export function logLike64(a: ArrayInt64): ArrayInt64 {218 // Math.floor(Math.log(hi * 2**32 + low) / Math.log(2)) <= Math.floor(Math.log(2**64) / Math.log(2)) = 64219 return {220 sign: a.sign,221 data: [0, Math.floor(Math.log(a.data[0] * 0x100000000 + a.data[1]) / Math.log(2))],222 };223}224/** @internal */225const INDEX_POSITIVE_INFINITY: ArrayInt64 = { sign: 1, data: [2146435072, 0] }; // doubleToIndex(Number.MAX_VALUE) + 1;226/** @internal */227const INDEX_NEGATIVE_INFINITY: ArrayInt64 = { sign: -1, data: [2146435072, 1] }; // doubleToIndex(-Number.MAX_VALUE) - 1228/**229 * Decompose a 64-bit floating point number into a significand and exponent230 * such that:231 * - significand over 53 bits including sign (also referred as fraction)232 * - exponent over 11 bits including sign233 * - whenever there are multiple possibilities we take the one having the highest significand (in abs)234 * - Number.MAX_VALUE = 2**1023 * (1 + (2**52-1)/2**52)235 * = 2**1023 * (2 - Number.EPSILON)236 * - Number.MIN_VALUE = 2**(-1022) * 2**(-52)237 * - Number.EPSILON = 2**(-52)238 *239 * @param d - 64-bit floating point number to be decomposed into (significand, exponent)240 *241 * @internal242 */243export function decomposeDouble(d: number): { exponent: number; significand: number } {244 // 1 => significand 0b1 - exponent 1 (will be preferred)245 // => significand 0b0.1 - exponent 2246 const maxSignificand = 2 - Number.EPSILON;247 for (let exponent = -1022; exponent !== 1024; ++exponent) {248 const powExponent = 2 ** exponent;249 const maxForExponent = maxSignificand * powExponent;250 if (Math.abs(d) <= maxForExponent) {251 return { exponent, significand: d / powExponent };252 }253 }254 return { exponent: Number.NaN, significand: Number.NaN };255}256/** @internal */257function positiveNumberToInt64(n: number): ArrayInt64["data"] {258 return [~~(n / 0x100000000), n >>> 0];259}260/** @internal */261function indexInDoubleFromDecomp(exponent: number, significand: number): ArrayInt64["data"] {262 // WARNING: significand >= 0263 // By construct of significand in decomposeDouble,264 // significand is always max-ed.265 // The double close to zero are the only one having a significand <1, they also have an exponent of -1022.266 // They are in range: [2**(-1022) * 2**(-52), 2**(-1022) * (2 - 2 ** 52)]267 // In other words there are 2**53 elements in that range if we include zero.268 // All other ranges (other exponents) have a length of 2**52 elements.269 if (exponent === -1022) {270 // We want the significand to be an integer value (like an index)271 const rescaledSignificand = significand * 2 ** 52; // significand * 2**52272 return positiveNumberToInt64(rescaledSignificand);273 }274 // Offset due to exp = -1022 + Offset of previous exp (excl. -1022) + Offset in current exp275 // 2**53 + (exponent - (-1022) -1) * 2**52 + (significand - 1) * 2**52276 // (exponent + 1023) * 2**52 + (significand - 1) * 2**52277 const rescaledSignificand = (significand - 1) * 2 ** 52; // (significand-1) * 2**52278 const exponentOnlyHigh = (exponent + 1023) * 2 ** 20; // (exponent + 1023) * 2**52 => [high: (exponent + 1023) * 2**20, low: 0]279 const index = positiveNumberToInt64(rescaledSignificand);280 index[0] += exponentOnlyHigh;281 return index;282}283/**284 * Compute the index of d relative to other available 64-bit floating point numbers285 * Rq: Produces negative indexes for negative doubles286 *287 * @param d - 64-bit floating point number, anything except NaN288 *289 * @internal290 */291export function doubleToIndex(d: number): ArrayInt64 {292 if (d === Number.POSITIVE_INFINITY) {293 return clone64(INDEX_POSITIVE_INFINITY);294 }295 if (d === Number.NEGATIVE_INFINITY) {296 return clone64(INDEX_NEGATIVE_INFINITY);297 }298 const decomp = decomposeDouble(d);299 const exponent = decomp.exponent;300 const significand = decomp.significand;301 if (d > 0 || (d === 0 && 1 / d === Number.POSITIVE_INFINITY)) {302 return { sign: 1, data: indexInDoubleFromDecomp(exponent, significand) };303 } else {304 const indexOpposite = indexInDoubleFromDecomp(exponent, -significand);305 if (indexOpposite[1] === 0xffffffff) {306 indexOpposite[0] += 1;307 indexOpposite[1] = 0;308 } else {309 indexOpposite[1] += 1;310 }311 return { sign: -1, data: indexOpposite }; // -indexInDoubleFromDecomp(exponent, -significand) - 1312 }313}314/**315 * Compute the 64-bit floating point number corresponding to the provided indexes316 *317 * @param n - index of the double318 *319 * @internal320 */321export function indexToDouble(index: ArrayInt64): number {322 if (index.sign === -1) {323 const indexOpposite: ArrayInt64 = { sign: 1, data: [index.data[0], index.data[1]] };324 if (indexOpposite.data[1] === 0) {325 indexOpposite.data[0] -= 1;326 indexOpposite.data[1] = 0xffffffff;327 } else {328 indexOpposite.data[1] -= 1;329 }330 return -indexToDouble(indexOpposite); // -indexToDouble(-index - 1);331 }332 if (isEqual64(index, INDEX_POSITIVE_INFINITY)) {333 return Number.POSITIVE_INFINITY;334 }335 if (index.data[0] < 0x200000) {336 // if: index < 2 ** 53 <--> index[0] < 2 ** (53-32) = 0x20_0000337 // The first 2**53 elements correspond to values having338 // exponent = -1022 and significand = index * Number.EPSILON339 // double value = index * 2 ** -1022 * Number.EPSILON340 // = index * 2 ** -1022 * 2 ** -52341 // = index * 2 ** -1074342 return (index.data[0] * 0x100000000 + index.data[1]) * 2 ** -1074;343 }344 const postIndexHigh = index.data[0] - 0x200000; // postIndex = index - 2 ** 53345 // exponent = -1021 + Math.floor(postIndex / 2**52)346 // = -1021 + Math.floor(postIndexHigh / 2**(52-32))347 // = -1021 + Math.floor(postIndexHigh / 2**20)348 // = -1021 + (postIndexHigh >> 20)349 const exponent = -1021 + (postIndexHigh >> 20);350 // significand = 1 + (postIndex % 2**52) / 2**52351 // = 1 + ((postIndexHigh * 2**32 + postIndexLow) % 2**52) / 2**52352 // = 1 + ((postIndexHigh % 2**20) * 2**32 + postIndexLow) / 2**52353 // = 1 + ((postIndexHigh & 0xfffff) * 2**32 + postIndexLow) / 2**52354 // = 1 + ((postIndexHigh & 0xfffff) * 2**32 + postIndexLow) * Number.EPSILON355 const significand = 1 + ((postIndexHigh & 0xfffff) * 2 ** 32 + index.data[1]) * Number.EPSILON;356 return significand * 2 ** exponent;357}358/**359 * Same as {@link doubleToIndex} except it throws in case of invalid double360 *361 * @internal362 */363export function safeDoubleToIndex(d: number, label: string): IO<never, never, ArrayInt64> {364 if (Number.isNaN(d)) {365 // Number.NaN does not have any associated index in the current implementation366 return IO.haltNow(new Error("fc.doubleNext constraints." + label + " must be a 32-bit float"));367 }368 return IO.succeedNow(doubleToIndex(d));369}370const EPSILON = Math.pow(2, -52);371const MAX_VALUE = (2 - EPSILON) * Math.pow(2, 1023);372const MIN_VALUE = Math.pow(2, -1022);373export function nextUp(x: number) {374 if (x !== x) {375 return x;376 }377 if (x === -1 / 0) {378 return -MAX_VALUE;379 }380 if (x === +1 / 0) {381 return +1 / 0;382 }383 if (x === +MAX_VALUE) {384 return +1 / 0;385 }386 let y = x * (x < 0 ? 1 - EPSILON / 2 : 1 + EPSILON);387 if (y === x) {388 y = MIN_VALUE * EPSILON > 0 ? x + MIN_VALUE * EPSILON : x + MIN_VALUE;389 }390 if (y === +1 / 0) {391 y = +MAX_VALUE;392 }393 const b = x + (y - x) / 2;394 if (x < b && b < y) {395 y = b;396 }397 const c = (y + x) / 2;398 if (x < c && c < y) {399 y = c;400 }401 return y === 0 ? -0 : y;402}403export function nextAfter(x: number, y: number) {404 return y < x ? -nextUp(-x) : y > x ? nextUp(x) : x !== x ? x : y;405}406export function computeBiasedRanges(407 min: ArrayInt64,408 max: ArrayInt64,409 biasedRanges?: { min: ArrayInt64; max: ArrayInt64 }[],410): { min: ArrayInt64; max: ArrayInt64 }[] {411 if (biasedRanges != null) {412 return biasedRanges;413 }414 if (isEqual64(min, max)) {415 return [{ min, max }];416 }417 const minStrictlySmallerThanZero = isStrictlyNegative64(min);418 const maxStrictlyGreaterThanZero = isStrictlyPositive64(max);419 if (minStrictlySmallerThanZero && maxStrictlyGreaterThanZero) {420 const logMin = logLike64(min);421 const logMax = logLike64(max);422 return [423 { min: logMin, max: logMax },424 { min: substract64(max, logMax), max },425 { min, max: substract64(min, logMin) },426 ];427 } else {428 const logGap = logLike64(substract64(max, min));429 const closeToMin = { min, max: add64(min, logGap) };430 const closeToMax = { min: substract64(max, logGap), max };431 return minStrictlySmallerThanZero ? [closeToMax, closeToMin] : [closeToMin, closeToMax];432 }433}434export function computeArrayInt64GenerateRange(435 min: ArrayInt64,436 max: ArrayInt64,437 biasFactor: number | undefined,438 biasedRanges: { min: ArrayInt64; max: ArrayInt64 }[] | undefined,439): UIO<{ min: ArrayInt64; max: ArrayInt64 }> {440 return IO.gen(function* (_) {441 if (biasFactor === undefined || (yield* _(Random.nextIntBetween(1, biasFactor))) !== 1) {442 return { min, max };443 }444 const ranges = computeBiasedRanges(min, max, biasedRanges);445 if (ranges.length === 1) {446 return ranges[0]!;447 }448 const id = yield* _(Random.nextIntBetween(-2 * (ranges.length - 1), ranges.length - 2));449 return id < 0 ? ranges[0]! : ranges[id + 1]!;450 });451}452export function clamp(n: number, min: number, max: number): number {453 return n < min ? min : n > max ? max : n;...`

LegendUtils.js

Source:LegendUtils.js

`1import _ from 'lodash'2class LegendUtils {3 static normalizedZtoRadius (scale, normalizedZ) {4 // z values are multiplied by the point size and a constant multiplier (50/3)5 // the constant multiplier makes LabeledScatter behave consistently with flipStandardCharts::Scatter6 // it means that when point.radius = 3 (default), the largest marker will have a radius of 50 pixels7 return (Math.sqrt(normalizedZ / Math.PI) * scale * 50 / 3)8 }9 static getLegendBubbles (maxZ, zPrefix, zSuffix) {10 const bubbleSizes = this.getLegendBubbleSizes(maxZ)11 const bubbleLabels = this.getLegendBubbleLabels(bubbleSizes, zPrefix, zSuffix)12 const legendBubbles = {13 large: {14 size: bubbleSizes[0],15 label: bubbleLabels[0],16 },17 medium: {18 size: bubbleSizes[1],19 label: bubbleLabels[1],20 },21 small: {22 size: bubbleSizes[2],23 label: bubbleLabels[2],24 },25 maxSize: Math.max(maxZ, bubbleSizes[0]),26 }27 return legendBubbles28 }29 static getLegendBubbleSizes (maxZ) {30 const significands = this.getBubbleSizeSignificands(maxZ)31 const exponent = this.getExponent(maxZ)32 return significands.map(x => x * (10 ** exponent))33 }34 static getBubbleSizeSignificands (maxZ) {35 const significand = this.getSignificand(maxZ)36 const maxSignificand = this.roundSignificand(significand)37 if (maxSignificand === 10) {38 return [maxSignificand, 5, 1]39 } else if (maxSignificand === 7) {40 return [maxSignificand, 3, 1]41 } else if (maxSignificand >= 6) {42 return [maxSignificand, 3, 1]43 } else if (maxSignificand === 5) {44 return [maxSignificand, 2, 0.5]45 } else if (maxSignificand === 4) {46 return [maxSignificand, 2, 0.5]47 } else if (maxSignificand === 3) {48 return [maxSignificand, 1.5, 0.5]49 } else if (maxSignificand === 2) {50 return [maxSignificand, 1, 0.2]51 } else if (maxSignificand === 1.5) {52 return [maxSignificand, 0.7, 0.2]53 } else { // maxSignificand === 154 return [maxSignificand, 0.5, 0.1] // consistent with maxSignificand == 1055 }56 }57 // Returns 10, 7, 6, 5, 4, 3, 2, 1.5 or 1 (exclude 8 and 9 because it is better to round those up to 10)58 static roundSignificand (significand) {59 if (significand >= 8) {60 return 1061 } else if (significand >= 7.5) {62 return 763 } else if (significand >= 2) {64 return Math.round(significand)65 } else {66 return Math.round(2 * significand) / 267 }68 }69 // For example if value is 123.45, then this returns 1.234570 static getSignificand (value) {71 return Number(value.toExponential().split('e')[0])72 }73 static getExponent (value) {74 return Number(value.toExponential().split('e')[1])75 }76 static getLegendBubbleLabels (bubbleSizes, prefix, suffix) {77 const oneThousand = 10 ** 378 const oneMillion = 10 ** 679 const oneBillion = 10 ** 980 const oneTrillion = 10 ** 1281 if (bubbleSizes[0] >= oneTrillion) {82 return bubbleSizes.map(x => this.formatBubbleSize(x, oneTrillion, 'T', prefix, suffix))83 } else if (bubbleSizes[0] >= oneBillion) {84 return bubbleSizes.map(x => this.formatBubbleSize(x, oneBillion, 'B', prefix, suffix))85 } else if (bubbleSizes[0] >= oneMillion) {86 return bubbleSizes.map(x => this.formatBubbleSize(x, oneMillion, 'M', prefix, suffix))87 } else if (bubbleSizes[0] >= oneThousand) {88 return bubbleSizes.map(x => this.formatBubbleSize(x, oneThousand, 'K', prefix, suffix))89 } else { // bubbleSizes[0] < 100090 return bubbleSizes.map(x => this.formatBubbleSize(x, 1, '', prefix, suffix))91 }92 }93 static formatBubbleSize (bubbleSize, denominator, denominatorLetter, prefix, suffix) {94 // Round to 2 significant figures to avoid numerical issues when formatting as string95 // The bubble sizes have no more than 2 significant figures96 const denominatedSize = Number((bubbleSize / denominator).toPrecision(2))97 return prefix + this.removePrecedingZero(denominatedSize.toString()) + denominatorLetter + suffix98 }99 static removePrecedingZero (label) {100 if (_.isString(label) && label.charAt(0) === '0') {101 return label.substring(1, label.length)102 } else {103 return label104 }105 }106 static normalizeZValues (Z, maxZ) {107 return _.map(Z, (z) => {108 return z / maxZ109 })110 }111 static setupBubbles (vb, legendBubbles, legend, pointRadius) {112 const rTop = this.normalizedZtoRadius(pointRadius, legendBubbles.large.size / legendBubbles.maxSize)113 const rMid = this.normalizedZtoRadius(pointRadius, legendBubbles.medium.size / legendBubbles.maxSize)114 const rBot = this.normalizedZtoRadius(pointRadius, legendBubbles.small.size / legendBubbles.maxSize)115 const cx = vb.x + vb.width + (legend.getWidth() / 2)116 const viewBoxYBottom = vb.y + vb.height117 const bubbleTextPadding = 2118 legend.setBubblesMaxWidth(rTop * 2)119 legend.setBubbles([120 {121 cx,122 cy: viewBoxYBottom - rTop,123 r: rTop,124 x: cx,125 y: viewBoxYBottom - (2 * rTop) - bubbleTextPadding,126 text: legendBubbles.large.label,127 },128 {129 cx,130 cy: viewBoxYBottom - rMid,131 r: rMid,132 x: cx,133 y: viewBoxYBottom - (2 * rMid) - bubbleTextPadding,134 text: legendBubbles.medium.label,135 },136 {137 cx,138 cy: viewBoxYBottom - rBot,139 r: rBot,140 x: cx,141 y: viewBoxYBottom - (2 * rBot) - bubbleTextPadding,142 text: legendBubbles.small.label,143 },144 ])145 legend.setBubblesTitle([146 {147 x: cx,148 y: viewBoxYBottom - (2 * rTop) - bubbleTextPadding,149 },150 ])151 }152}...`

FloatHelpers.ts

Source:FloatHelpers.ts

`1const safeNumberIsInteger = Number.isInteger;2const safeNumberIsNaN = Number.isNaN;3const safeNegativeInfinity = Number.NEGATIVE_INFINITY;4const safePositiveInfinity = Number.POSITIVE_INFINITY;5const safeNaN = Number.NaN;6/** @internal */7export const MIN_VALUE_32 = 2 ** -126 * 2 ** -23;8/** @internal */9export const MAX_VALUE_32 = 2 ** 127 * (1 + (2 ** 23 - 1) / 2 ** 23);10/** @internal */11export const EPSILON_32 = 2 ** -23;12/** @internal */13const INDEX_POSITIVE_INFINITY = 2139095040; // floatToIndex(MAX_VALUE_32) + 1;14/** @internal */15const INDEX_NEGATIVE_INFINITY = -2139095041; // floatToIndex(-MAX_VALUE_32) - 116/**17 * Decompose a 32-bit floating point number into a significand and exponent18 * such that:19 * - significand over 24 bits including sign (also referred as fraction)20 * - exponent over 8 bits including sign21 * - whenever there are multiple possibilities we take the one having the highest significand (in abs)22 *23 * Remark in 64-bit floating point number:24 * - significand is over 53 bits including sign25 * - exponent is over 11 bits including sign26 * - Number.MAX_VALUE = 2**1023 * (1 + (2**52-1)/2**52)27 * - Number.MIN_VALUE = 2**(-1022) * 2**(-52)28 * - Number.EPSILON = 2**(-52)29 *30 * @param f - 32-bit floating point number to be decomposed into (significand, exponent)31 *32 * @internal33 */34export function decomposeFloat(f: number): { exponent: number; significand: number } {35 // 1 => significand 0b1 - exponent 1 (will be preferred)36 // => significand 0b0.1 - exponent 237 const maxSignificand = 1 + (2 ** 23 - 1) / 2 ** 23;38 for (let exponent = -126; exponent !== 128; ++exponent) {39 const powExponent = 2 ** exponent;40 const maxForExponent = maxSignificand * powExponent;41 if (Math.abs(f) <= maxForExponent) {42 return { exponent, significand: f / powExponent };43 }44 }45 return { exponent: safeNaN, significand: safeNaN };46}47/** @internal */48function indexInFloatFromDecomp(exponent: number, significand: number) {49 // WARNING: significand >= 050 // By construct of significand in decomposeFloat,51 // significand is always max-ed.52 // The float close to zero are the only one having a significand <1, they also have an exponent of -126.53 // They are in range: [2**(-126) * 2**(-23), 2**(-126) * (2 - 2 ** 23)]54 // In other words there are 2**24 elements in that range if we include zero.55 // All other ranges (other exponents) have a length of 2**23 elements.56 if (exponent === -126) {57 return significand * 0x800000; // significand * 2**2358 }59 // Offset due to exp = -126 + Offset of previous exp (excl. -126) + Offset in current exp60 // 2**24 + (exponent - (-126) -1) * 2**23 + (significand - 1) * 2**2361 return (exponent + 127) * 0x800000 + (significand - 1) * 0x800000;62}63/**64 * Compute the index of f relative to other available 32-bit floating point numbers65 * Rq: Produces negative indexes for negative floats66 *67 * @param f - 32-bit floating point number68 *69 * @internal70 */71export function floatToIndex(f: number): number {72 if (f === safePositiveInfinity) {73 return INDEX_POSITIVE_INFINITY;74 }75 if (f === safeNegativeInfinity) {76 return INDEX_NEGATIVE_INFINITY;77 }78 const decomp = decomposeFloat(f);79 const exponent = decomp.exponent;80 const significand = decomp.significand;81 if (safeNumberIsNaN(exponent) || safeNumberIsNaN(significand) || !safeNumberIsInteger(significand * 0x800000)) {82 return safeNaN;83 }84 if (f > 0 || (f === 0 && 1 / f === safePositiveInfinity)) {85 return indexInFloatFromDecomp(exponent, significand);86 } else {87 return -indexInFloatFromDecomp(exponent, -significand) - 1;88 }89}90/**91 * Compute the 32-bit floating point number corresponding to the provided indexes92 *93 * @param n - index of the float94 *95 * @internal96 */97export function indexToFloat(index: number): number {98 if (index < 0) {99 return -indexToFloat(-index - 1);100 }101 if (index === INDEX_POSITIVE_INFINITY) {102 return safePositiveInfinity;103 }104 if (index < 0x1000000) {105 // The first 2**24 elements correspond to values having106 // exponent = -126 and significand = index * 2**(-23)107 return index * 2 ** -149;108 }109 const postIndex = index - 0x1000000;110 // Math.floor(postIndex / 0x800000) = Math.floor(postIndex / 2**23) = (postIndex >> 23)111 const exponent = -125 + (postIndex >> 23);112 // (postIndex % 0x800000) / 0x800000 = (postIndex & 0x7fffff) / 0x800000113 const significand = 1 + (postIndex & 0x7fffff) / 0x800000;114 return significand * 2 ** exponent;...`

Using AI Code Generation

`1const {maxSignificand} = require('fast-check-monorepo');2console.log(maxSignificand(5));3const {maxSignificand} = require('fast-check-monorepo');4console.log(maxSignificand(5));5const {maxSignificand} = require('fast-check-monorepo');6console.log(maxSignificand(5));7const {maxSignificand} = require('fast-check-monorepo');8console.log(maxSignificand(5));9const {maxSignificand} = require('fast-check-monorepo');10console.log(maxSignificand(5));11const {maxSignificand} = require('fast-check-monorepo');12console.log(maxSignificand(5));13const {maxSignificand} = require('fast-check-monorepo');14console.log(maxSignificand(5));15const {maxSignificand} = require('fast-check-monorepo');16console.log(maxSignificand(5));17const {maxSignificand} = require('fast-check-monorepo');18console.log(maxSignificand(5));19const {maxSignificand} = require('fast-check-monorepo');20console.log(maxSignificand(5));21const {maxSignificand} = require('fast-check-monorepo');`

Using AI Code Generation

`1import {maxSignificand} from 'fast-check-monorepo'2console.log(maxSignificand(1, 2))3import {maxSignificand} from 'fast-check-monorepo'4console.log(maxSignificand(1, 2))5import {maxSignificand} from 'fast-check-monorepo'6console.log(maxSignificand(1, 2))7import {maxSignificand} from 'fast-check-monorepo'8console.log(maxSignificand(1, 2))9import {maxSignificand} from 'fast-check-monorepo'10console.log(maxSignificand(1, 2))11import {maxSignificand} from 'fast-check-monorepo'12console.log(maxSignificand(1, 2))13import {maxSignificand} from 'fast-check-monorepo'14console.log(maxSignificand(1, 2))15import {maxSignificand} from 'fast-check-monorepo'16console.log(maxSignificand(1, 2))17import {maxSignificand} from 'fast-check-monorepo'18console.log(maxSignificand(1, 2))19import {maxSignificand} from 'fast-check-monorepo'20console.log(maxSignificand(1, 2))`

Using AI Code Generation

`1const fc = require('fast-check')2const { maxSignificand } = require('fast-check/lib/arbitrary/helpers/FloatArbitraryHelpers.js')3console.log(maxSignificand(1, 8))4console.log(maxSignificand(1, 16))5console.log(maxSignificand(1, 24))6console.log(maxSignificand(1, 32))7const fc = require('fast-check')8const { maxSignificand } = require('fast-check/lib/arbitrary/helpers/FloatArbitraryHelpers.js')9console.log(maxSignificand(1, 8))10console.log(maxSignificand(1, 16))11console.log(maxSignificand(1, 24))12console.log(maxSignificand(1, 32))13const fc = require('fast-check')14const { maxSignificand } = require('fast-check/lib/arbitrary/helpers/FloatArbitraryHelpers.js')15console.log(maxSignificand(1, 8))16console.log(maxSignificand(1, 16))17console.log(maxSignificand(1, 24))18console.log(maxSignificand(1, 32))19const fc = require('fast-check')20const { maxSignificand } = require('fast-check/lib/arbitrary/helpers/FloatArbitraryHelpers.js')21console.log(maxSignificand(1, 8))22console.log(maxSignificand(1, 16))23console.log(maxSignificand(1, 24))24console.log(maxSignificand(1, 32))25const fc = require('fast-check')26const { maxSignificand } = require('fast-check/lib/arbitrary/helpers/FloatArbitraryHelpers.js')27console.log(maxSignificand(1, 8))28console.log(maxSignificand(1, 16))29console.log(maxSignificand(1, 24))30console.log(maxSignificand(1, 32))`

Using AI Code Generation

`1const fc = require('fast-check')2const {maxSignificand} = require('fast-check-monorepo')3test('maxSignificand', () => {4 fc.assert(5 fc.property(fc.integer(), (n) => {6 if (n >= 0) {7 expect(maxSignificand(n)).toBe(Math.pow(10, n) - 1)8 } else {9 expect(maxSignificand(n)).toBe(0)10 }11 })12})`

Using AI Code Generation

`1const fc = require('fast-check');2const {maxSignificand} = require('fast-check-monorepo');3const {maxSignificand} = require('fast-check-monorepo');4const min = 1;5const max = 10;6const test = fc.property(fc.integer(min, max), (x) => {7 return x >= min && x <= max;8});9fc.assert(test, { numRuns: 1000 });10const fc = require('fast-check');11const {maxSignificand} = require('fast-check-monorepo');12const min = 1;13const max = 10;14const test = fc.property(fc.integer(min, max), (x) => {15 return x >= min && x <= max;16});17fc.assert(test, { numRuns: 1000 });18const fc = require('fast-check');19const {maxSignificand} = require('fast-check-monorepo');20const min = 1;21const max = 10;22const test = fc.property(fc.integer(min, max), (x) => {23 return x >= min && x <= max;24});25fc.assert(test, { numRuns: 1000 });26const fc = require('fast-check');27const {maxSignificand} = require('fast-check-monorepo');28const min = 1;29const max = 10;30const test = fc.property(fc.integer(min, max), (x) => {31 return x >= min && x <= max;32});33fc.assert(test, { numRuns: 1000 });34const fc = require('fast-check');35const {maxSignificand} = require('fast-check-monorepo');36const min = 1;37const max = 10;38const test = fc.property(fc.integer(min, max), (x) => {39 return x >= min && x <= max;40});41fc.assert(test, { numRuns: 1000 });42const fc = require('fast-check');43const {maxSignificand} = require('fast-check-monorepo');`

Using AI Code Generation

`1const fc = require('fast-check');2const {maxSignificand} = require('fast-check-monorepo');3test('maxSignificand', () => {4 fc.assert(5 fc.property(fc.float(), fc.float(), (a, b) => {6 const result = maxSignificand(a, b);7 return result >= a && result >= b;8 })9 );10});11const fc = require('fast-check');12const {maxSignificand} = require('fast-check-monorepo');13test('maxSignificand', () => {14 fc.assert(15 fc.property(fc.float(), fc.float(), (a, b) => {16 const result = maxSignificand(a, b);17 return result >= a && result >= b;18 })19 );20});21const fc = require('fast-check');22const {maxSignificand} = require('fast-check-monorepo');23test('maxSignificand', () => {24 fc.assert(25 fc.property(fc.float(), fc.float(), (a, b) => {26 const result = maxSignificand(a, b);27 return result >= a && result >= b;28 })29 );30});31const fc = require('fast-check');32const {maxSignificand} = require('fast-check-monorepo');33test('maxSignificand', () => {34 fc.assert(35 fc.property(fc.float(), fc.float(), (a, b) => {36 const result = maxSignificand(a, b);37 return result >= a && result >= b;38 })39 );40});41const fc = require('fast-check');42const {maxSignificand} = require('fast-check-monorepo');`

Using AI Code Generation

`1const fc = require('fast-check');2const { maxSignificand } = require('fast-check-monorepo');3const maxSigGen = maxSignificand(3);4fc.assert(fc.property(maxSigGen, (n) => {5 const numDigits = n.toString().length - 1;6 return numDigits <= 3;7}));`

Using AI Code Generation

`1const fc = require('fast-check');2const assert = require('assert');3const maxSignificand = require('./maxSignificand');4const isInteger = (v) => Number.isInteger(v) && v >= 0;5const isPositive = (v) => v > 0;6describe('maxSignificand', () => {7 it('should return 1 when input is 0', () => {8 assert.strictEqual(maxSignificand(0), 1);9 });10 it('should return 1 when input is 1', () => {11 assert.strictEqual(maxSignificand(1), 1);12 });13 it('should return 1 when input is 2', () => {14 assert.strictEqual(maxSignificand(2), 1);15 });16 it('should return 2 when input is 3', () => {17 assert.strictEqual(maxSignificand(3), 2);18 });19 it('should return 2 when input is 4', () => {20 assert.strictEqual(maxSignificand(4), 2);21 });22 it('should return 3 when input is 5', () => {23 assert.strictEqual(maxSignificand(5), 3);24 });25 it('should return 3 when input is 6', () => {26 assert.strictEqual(maxSignificand(6), 3);27 });28 it('should return 4 when input is 7', () => {29 assert.strictEqual(maxSignificand(7), 4);30 });31 it('should return 4 when input is 8', () => {32 assert.strictEqual(maxSignificand(8), 4);33 });34 it('should return 5 when input is 9', () => {35 assert.strictEqual(maxSignificand(9), 5);36 });37 it('should return 5 when input is 10', () => {38 assert.strictEqual(maxSignificand(10), 5);39 });40 it('should return 6 when input is 11', () => {41 assert.strictEqual(maxSignificand(11), 6);42 });43 it('should return 6 when input is 12', () => {44 assert.strictEqual(maxSignificand(12), 6);45 });46 it('should return 7 when input is`

## Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.