@@ -2,19 +2,26 @@ import { TypeDefinition } from '../types';
22
33import { FormatError } from '../core/Error' ;
44import { NamedEntity } from '../core/NamedEntity' ;
5- import { Value } from '../core/Value' ;
65
7- import { base10ToIeee754 , ieee754ToBase10 , isNumber } from '../utils' ;
6+ import { base10ToIeee754 , getNumericInputRange , ieee754ToBase10 , isNumber } from '../utils' ;
87
9- export class FloatValue extends Value < number > implements NamedEntity {
10- public constructor ( public readonly definition : Readonly < Pick < TypeDefinition , 'name' | 'size' > > ) {
11- super ( ) ;
8+ import { NumericValue } from './NumericValue' ;
9+
10+ export class FloatValue extends NumericValue implements NamedEntity {
11+ public constructor (
12+ public readonly definition : Readonly < Pick < TypeDefinition , 'name' | 'size' | 'validation' > > ,
13+ ) {
14+ super ( definition ) ;
1215 }
1316
1417 public get name ( ) {
1518 return this . definition . name ;
1619 }
1720
21+ public get range ( ) {
22+ return getNumericInputRange ( this . size ) ;
23+ }
24+
1825 public get size ( ) {
1926 return this . definition . size || 4 ;
2027 }
@@ -24,8 +31,7 @@ export class FloatValue extends Value<number> implements NamedEntity {
2431 }
2532
2633 public decode ( bytes : number [ ] ) {
27- this . _value = ieee754ToBase10 ( bytes , this . size ) ;
28- return this ;
34+ return this . setValue ( ieee754ToBase10 ( bytes , this . size ) ) ;
2935 }
3036
3137 public fromJSON ( payload : unknown ) {
@@ -38,11 +44,6 @@ export class FloatValue extends Value<number> implements NamedEntity {
3844 return this ;
3945 }
4046
41- public setValue ( value : number ) {
42- this . _value = value ;
43- return this ;
44- }
45-
4647 public toString ( ) {
4748 return ( this . _value ?? NaN ) . toPrecision ( 7 ) ;
4849 }
0 commit comments