@@ -121,14 +121,28 @@ static bool format_output(RNum *num, char mode, const char *s, RaxMode m, RaxAct
121121	case  'f' :
122122		printf  ("%.01lf\n" , num -> fvalue );
123123		break ;
124- 	case  'l' :
124+ 		 case  'l' :
125125		{
126126			R_STATIC_ASSERT  (sizeof  (float ) ==  4 );
127127			float  f  =  (float )num -> fvalue ;
128128			ut32  * p  =  (ut32  * )& f ;
129129			printf  ("Fx%08x\n" , * p );
130130		}
131131		break ;
132+ 	case  'g' :
133+ 		{
134+ 			R_STATIC_ASSERT  (sizeof  (float ) ==  4 );
135+ 			float  f  =  (float )num -> fvalue ;
136+ 			ut16  bf16  =  r_num_float_to_bf16  (f );
137+ 			printf  ("Gx%04x\n" , bf16 );
138+ 		}
139+ 		break ;
140+ 	case  'G' :
141+ 		{
142+ 			float  f  =  r_num_bf16_to_float  ((ut16 )n );
143+ 			printf  ("%.9g\n" , f );
144+ 		}
145+ 		break ;
132146	case  'O' : printf  ("0%"  PFMT64o  "\n" , n ); break ;
133147	case  'B' :
134148		if  (n ) {
@@ -147,7 +161,7 @@ static bool format_output(RNum *num, char mode, const char *s, RaxMode m, RaxAct
147161		}
148162		break ;
149163	default :
150- 		R_LOG_ERROR  ("Unknown output mode %d " , m .omode );
164+ 		R_LOG_ERROR  ("Unknown output mode %c " , m .omode );
151165		return  false;
152166	}
153167	return  true;
@@ -169,6 +183,8 @@ static int help(void) {
169183		"  ternary    ->  int              ;  rax2 1010dt\n" 
170184		"  float      ->  hex              ;  rax2 3.33f\n" 
171185		"  hex        ->  float            ;  rax2 Fx40551ed8\n" 
186+ 		"  BF16       ->  hex              ;  rax2 1.5g\n" 
187+ 		"  hex        ->  BF16             ;  rax2 Gx3f80\n" 
172188		"  oct        ->  hex              ;  rax2 35o\n" 
173189		"  hex        ->  oct              ;  rax2 Ox12 (O is a letter)\n" 
174190		"  bin        ->  hex              ;  rax2 1100011b\n" 
@@ -588,6 +604,7 @@ static bool rax(RNum *num, char *str, int len, int last, RaxActions *flags, RaxM
588604		memcpy  (& f , & n , sizeof  (f ));
589605		memcpy  (& d , & n , sizeof  (d ));
590606		printf  ("float   %ff\n" , f );
607+ 		printf  ("bf16    Gx%04x\n" , r_num_float_to_bf16  (f ));
591608		printf  ("double  %lf\n" , d );
592609		printf  ("binary  0b%s\n" , out );
593610
@@ -647,6 +664,7 @@ static bool rax(RNum *num, char *str, int len, int last, RaxActions *flags, RaxM
647664
648665		pj_ks  (* pj , "fvalue" , r_strf  ("%.1lf" , num -> fvalue ));
649666		pj_ks  (* pj , "float" , r_strf  ("%ff" , f ));
667+ 		pj_ks  (* pj , "bf16" , r_strf  ("Gx%04x" , r_num_float_to_bf16  (f )));
650668		pj_ks  (* pj , "double" , r_strf  ("%lf" , d ));
651669		pj_ks  (* pj , "binary" , r_strf  ("0b%s" , out ));
652670		char  b36str [16 ];
@@ -756,6 +774,9 @@ static bool rax(RNum *num, char *str, int len, int last, RaxActions *flags, RaxM
756774	} else  if  (r_str_startswith  (str , "Bx" )) {
757775		out_mode  =  'B' ;
758776		* str  =  '0' ;
777+ 	} else  if  (r_str_startswith  (str , "Gx" )) {
778+ 		out_mode  =  'G' ;
779+ 		* str  =  '0' ;
759780	} else  if  (r_str_startswith  (str , "Tx" )) {
760781		out_mode  =  'T' ;
761782		* str  =  '0' ;
@@ -768,6 +789,8 @@ static bool rax(RNum *num, char *str, int len, int last, RaxActions *flags, RaxM
768789		// TODO: Move print into format_output 
769790	} else  if  (r_str_endswith  (str , "f" )) {
770791		out_mode  =  'l' ;
792+ 	} else  if  (r_str_endswith  (str , "g" )) {
793+ 		out_mode  =  'g' ;
771794	} else  if  (r_str_endswith  (str , "dt" )) {
772795		out_mode  =  'I' ;
773796		str [strlen  (str ) -  2 ] =  't' ;
0 commit comments