#include <stdio.h>
#include <math.h>
char toNotationUnit( double value, float * out) {
double val;
char notacoes[ ] = { 'y' , 'z' , 'a' , 'f' , 'p' , 'n' , 'u' , 'm' , ' ' , 'k' , 'M' , 'G' , 'T' , 'P' , 'E' , 'Z' , 'Y' } ;
int counter= 8 ;
char unit;
val = value> 0 ? value:- value;
if ( val < 1 ) {
while ( ( val < 1.00 ) & ( counter != 0 ) ) {
counter--;
val= val* ( double ) 1000 ;
}
} else {
while ( ( val >= 1000 ) & ( counter != 16 ) ) {
counter++;
val= val/ ( double ) 1000 ;
}
}
unit = notacoes[ counter] ;
val = round( val* ( double ) 100 ) / ( double ) 100 ;
* out = ( float ) value> 0 ? val:- val;
return unit;
}
int main( ) {
double x = - 1230000 ;
float res;
char t;
t = toNotationUnit( x,& res) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CmNoYXIgdG9Ob3RhdGlvblVuaXQoZG91YmxlIHZhbHVlLGZsb2F0ICpvdXQpIHsKICAgICAgICBkb3VibGUgdmFsOwoJCWNoYXIgbm90YWNvZXNbXSA9IHsneScsJ3onLCdhJywnZicsJ3AnLCduJywndScsJ20nLCcgJywnaycsJ00nLCdHJywnVCcsJ1AnLCdFJywnWicsJ1knfTsKICAgICAgICBpbnQgY291bnRlcj04OwogICAgICAgIGNoYXIgdW5pdDsKICAgICAgICB2YWwgPSB2YWx1ZT4wP3ZhbHVlOi12YWx1ZTsKICAgICAgICBpZih2YWwgPCAxKSB7CiAgICAgICAgICAgICAgICB3aGlsZSggKHZhbCA8IDEuMDApICYgKGNvdW50ZXIgIT0gMCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY291bnRlci0tOwogICAgICAgICAgICAgICAgICAgICAgICB2YWw9dmFsKihkb3VibGUpMTAwMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgIHdoaWxlKCh2YWwgPj0gMTAwMCkgJiAoY291bnRlciAhPSAxNikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY291bnRlcisrOwogICAgICAgICAgICAgICAgICAgICAgICB2YWw9dmFsLyhkb3VibGUpMTAwMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdW5pdCA9IG5vdGFjb2VzW2NvdW50ZXJdOwogICAgICAgIHZhbCA9IHJvdW5kKHZhbCooZG91YmxlKTEwMCkvKGRvdWJsZSkxMDA7CiAgICAgICAgKm91dCA9IChmbG9hdCkgdmFsdWU+MD92YWw6LXZhbDsKICAgICAgICByZXR1cm4gdW5pdDsKfQogCmludCBtYWluKCkgewogIGRvdWJsZSB4ID0gLTEyMzAwMDA7CiAgZmxvYXQgcmVzOwogIGNoYXIgdDsKICB0ID0gdG9Ob3RhdGlvblVuaXQoeCwmcmVzKTsKICBwcmludGYoIiUuMkYlYyIscmVzLHQpOwogIHJldHVybiAwOwp9