forum-msg-id-125860-edit

Original date:2014-12-25 01:02:02 Edited by: cargoan Subject: Re: bigatom.e - New ba_log10() function (fast)

ba_log10() sometimes, many times, returns more decimals than the scale if mode (SC_MODE) is not zero.

bigatom not counts leading zeros in small numbers (0.0...ddd...) and sum adds it when the res parameter is 0.0...ddd...

two possibilities:

-- fast 
export function ba_log10(object x, integer round = 0) 
   if not bigatom(x) then 
      x = ba_new(x) 
   end if 
    
   integer exponent = x[EXPONENT] + 1 
   x[EXPONENT] = -1 
   sequence res = ba_logb(x, 10, round) 
   res = ba_add(res, exponent)           -- la suma ignora la escala 
   if round then 
      res = round_digits(res, res[EXPONENT] + 2 + SCALE) 
   else 
      res[DIGITS] = remove(res[DIGITS], 
                           res[EXPONENT] + 2 + SCALE, 
                           length(res[DIGITS])) 
   end if 
 
   return normalize(res) 
end function 
-- 
 
 
-- KISS: Keep It Simple, Stupid!... ?????? 
-- KISS: Keep It Short, Simple... mejor as?... mucho mejor. 
export function ba_log10_2(object x, integer round = 0) 
   if not bigatom(x) then 
      x = ba_new(x) 
   end if 
    
   integer exponent = x[EXPONENT]  
   x[EXPONENT] = 0 
   sequence res = ba_logb(x, 10, round) 
 
   return ba_add(res, exponent) 
end function 
-- 
 

but:

┌───────────────────────────────────────────────────[mi?rcoles, 24 de diciembre  8:33 CET] 
├─[cargoan en ~cargoan/Documentos/Programaci?n/Euphoria/bigatom-a1] 
└─[bash 4.3]──[$]: tail -n 12 bigatom.e 
 
ifdef TEST2 then 
   scale(100, 1) 
   atom t0 = time() 
    -- exp = -1 and cut 
    ba_printf(1,"ba_log10('9999999999999999'):\n\t%B\n", ba_log10("9999999999999999") 
) 
   atom t1 = time() 
   printf(1, "en %.3f seg.\n\n", t1 - t0)  
   -- exp = 0  
   ba_printf(1,"ba_log10_2('9999999999999999'):\n\t%B\n", ba_log10_2("999999999999999 
9")) 
   printf(1, "en %.3f seg.\n", time() - t1)  
end ifdef 
┌───────────────────────────────────────────────────[mi?rcoles, 24 de diciembre  8:33 CET] 
├─[cargoan en ~cargoan/Documentos/Programaci?n/Euphoria/bigatom-a1] 
└─[bash 4.3]──[$]: eui -D TEST2 bigatom.e 
ba_log10('9999999999999999'): 
    15.99999999999999995657055180967481506341469859208020875008840375265452417821570583349 
34058543959866208 
en 0.820 seg. 
 
ba_log10_2('9999999999999999'): 
    15.99999999999999995657055180967481506341469859208020875008840375265452417821570583349 
34058543959866208 
en 1.500 seg. 
┌───────────────────────────────────────────────────[mi?rcoles, 24 de diciembre  8:33 CET] 
├─[cargoan en ~cargoan/Documentos/Programaci?n/Euphoria/bigatom-a1] 
└─[bash 4.3]──[$]: euc -D TEST2 bigatom.e 
Build directory: build-031070/ 
Translating code, pass: 1 2 3 4 5 6 7 8  generating 
Compiling with GCC 
Compiling  12% init-.c 
Compiling  50% bigatom.c 
Compiling  75% main-.c 
Linking 100% ../bigatom 
┌───────────────────────────────────────────────────[mi?rcoles, 24 de diciembre  8:33 CET] 
├─[cargoan en ~cargoan/Documentos/Programaci?n/Euphoria/bigatom-a1] 
└─[bash 4.3]──[$]: ./bigatom 
ba_log10('9999999999999999'): 
    15.99999999999999995657055180967481506341469859208020875008840375265452417821570583349 
34058543959866208 
en 0.250 seg. 
 
ba_log10_2('9999999999999999'): 
    15.99999999999999995657055180967481506341469859208020875008840375265452417821570583349 
34058543959866208 
en 0.410 seg. 
┌───────────────────────────────────────────────────[mi?rcoles, 24 de diciembre  8:33 CET] 
├─[cargoan en ~cargoan/Documentos/Programaci?n/Euphoria/bigatom-a1] 
└─[bash 4.3]──[$]:  grep "model name" /proc/cpuinfo | sort -u | sed 's/.*: //' ; cat /sys/ 
devices/system/cpu/cpu0/cpufreq/{scaling_governor,cpuinfo_max_freq}; uname -a  
AMD Athlon(tm) Dual Core Processor 4450e 
ondemand 
2300000 
Linux HP-s3733es 3.17.7-1-lqx #1 ZEN SMP PREEMPT Fri Dec 19 15:52:45 CET 2014 x86_64 GNU/L 
inux 
┌───────────────────────────────────────────────────[mi?rcoles, 24 de diciembre  8:33 CET] 
├─[cargoan en ~cargoan/Documentos/Programaci?n/Euphoria/bigatom-a1] 
└─[bash 4.3]──[$]: journalctl -b | grep -i smpboot | grep -i mips | sed 's|.*:*: ||'  
Total of 2 processors activated (9200.10 BogoMIPS) 
┌───────────────────────────────────────────────────[mi?rcoles, 24 de diciembre  8:33 CET] 
├─[cargoan en ~cargoan/Documentos/Programaci?n/Euphoria/bigatom-a1] 
└─[bash 4.3]──[$]: gcc --version | head -n 2 
gcc (GCC) 4.9.2 
Copyright (C) 2014 Free Software Foundation, Inc. 
 
 

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu