@@ -2,19 +2,26 @@ import { TypeDefinition } from '../types';
2
2
3
3
import { FormatError } from '../core/Error' ;
4
4
import { NamedEntity } from '../core/NamedEntity' ;
5
- import { Value } from '../core/Value' ;
6
5
7
- import { base10ToIeee754 , ieee754ToBase10 , isNumber } from '../utils' ;
6
+ import { base10ToIeee754 , getNumericInputRange , ieee754ToBase10 , isNumber } from '../utils' ;
8
7
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 ) ;
12
15
}
13
16
14
17
public get name ( ) {
15
18
return this . definition . name ;
16
19
}
17
20
21
+ public get range ( ) {
22
+ return getNumericInputRange ( this . size ) ;
23
+ }
24
+
18
25
public get size ( ) {
19
26
return this . definition . size || 4 ;
20
27
}
@@ -24,8 +31,7 @@ export class FloatValue extends Value<number> implements NamedEntity {
24
31
}
25
32
26
33
public decode ( bytes : number [ ] ) {
27
- this . _value = ieee754ToBase10 ( bytes , this . size ) ;
28
- return this ;
34
+ return this . setValue ( ieee754ToBase10 ( bytes , this . size ) ) ;
29
35
}
30
36
31
37
public fromJSON ( payload : unknown ) {
@@ -38,11 +44,6 @@ export class FloatValue extends Value<number> implements NamedEntity {
38
44
return this ;
39
45
}
40
46
41
- public setValue ( value : number ) {
42
- this . _value = value ;
43
- return this ;
44
- }
45
-
46
47
public toString ( ) {
47
48
return ( this . _value ?? NaN ) . toPrecision ( 7 ) ;
48
49
}
0 commit comments