Re: Phix, numbers, printf, log10

new topic     » goto parent     » topic index » view thread      » older message » newer message
petelomax said...
RobertS said...

printf(1, "%e", 12)
1.220000e+1

OK, I've aligned the "fwk" side with the "(f-digit)*10" side and got rid of fadj, and pushed all this to https://raw.githubusercontent.com/petelomax/Phix/master/builtins/VM/pprntfN.e which you may find much easier:

I copied that pprntfN.e file and rebuilt p.exe, but I'm afraid there is still something wrong:

printf(1, "%e", 38.24)
3.802400e+1

But this seems to be the last remaining issue for me.

I've written a replacement for to_number() that reliably reads 8.98e2 as integer (it removes the decimal point from the mantissa which thus becomes integer, and then adjust the exponent according to where the decimal point had been).

Also, I think I've resolved the "magnitude" issue (which I need for rounding numbers to n significant digits) — m is floor(log10(a)), which may possibly be wrong for values very close to powers of 10, but then I check if the following condition is met: power(10, m) <= a < power(10, m+1) — if not, m gets corrected. Not very elegant, but I think it works.

Should anyone be interested I'll gladly go into details.

So, apart from %e, and as long as nothing unexpected comes up, I think I have what I need!

Robert

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu