77 isIntegerType ,
88} from '@h5web/shared/guards' ;
99import {
10- type ComplexType ,
1110 type CompoundType ,
1211 DTypeClass ,
1312 type NumericType ,
@@ -37,30 +36,19 @@ export function createFloatFormatter(
3736 notation : Notation ,
3837) : ( val : number ) => string {
3938 switch ( notation ) {
40- case Notation . FixedPoint :
41- return format ( '.3f' ) ;
39+ case Notation . Exact :
40+ return ( val ) => val . toString ( ) ;
4241 case Notation . Scientific :
4342 return format ( '.3e' ) ;
4443 default :
4544 return format ( '.5~g' ) ;
4645 }
4746}
4847
49- export function createMatrixComplexFormatter (
48+ export function getFormatter < T extends PrintableType > (
49+ type : T ,
5050 notation : Notation ,
51- ) : ( val : ScalarValue < ComplexType > ) => string {
52- const formatStr =
53- notation === Notation . FixedPoint
54- ? '.2f'
55- : `.3~${ notation === Notation . Scientific ? 'e' : 'g' } ` ;
56-
57- return createComplexFormatter ( formatStr , true ) ;
58- }
59-
60- export function getFormatter (
61- type : PrintableType ,
62- notation : Notation ,
63- ) : ( val : ScalarValue < PrintableType > ) => string ; // override distributivity of `ValueFormatter`
51+ ) : ( val : ScalarValue < T > ) => string ; // override distributivity of `ValueFormatter`
6452
6553export function getFormatter (
6654 type : PrintableType ,
@@ -83,10 +71,13 @@ export function getFormatter(
8371 }
8472
8573 if ( isComplexType ( type ) ) {
86- return createMatrixComplexFormatter ( notation ) ;
74+ return createComplexFormatter (
75+ getFormatter ( type . realType , notation ) ,
76+ getFormatter ( type . imagType , notation ) ,
77+ ) ;
8778 }
8879
89- return ( val : string ) => val . toString ( ) ; // call `toString()` for safety, in case type cast is wrong
80+ return ( val : string ) => val . toString ( ) ;
9081}
9182
9283export function getCellWidth (
0 commit comments