This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

expr with large values

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

expr with large values

Post by Ofloo »

Code: Select all

% format %.2f [format %e [expr [format %e 9999999999999] * [format %e 9999999999999]]]
100000000000000004764729344.00
but if i calc it with my calc then its not right why is this ..?
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

An easier way to do it is:

expr 9999999999999.0 * 9999999999999.0
1e+26

You got:
100000000000000004764729344

which is the same thing.

The real value is 99999999999980000000000001. So it's approximately right. Not much of a difference between 0.999999999999 and 1.0.

But anyway, the reason is that computers' builtin floating point logic is not 100% accurate. It can only hold a certain amount of precision. To have 100% accuracy you have to use software methods which are slower.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

lol are u serious ? ???

its to create a long ip out of a ipv6 so one ip is next to an other there isn't that mutch difference either so .. i expect a calculation to be right .. not somewhere close to ...

so ur saying this is normal ? lol this sux.

k is there a way to avoid this then ?
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

hmm k i think i might of found a way do you know somehow how i can reformat this ::::: to

0:0:0:0:0:0

or :1:f::6: or 2001::d:::

so i have at least a char between every :

also how do i reformat this fe80::20b:cdff:fea4:6c5f%4

to a normal format

000000:000000:000000:000000:000000:000000
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Dude, please don't do ipv6 calculations in floating point. Use integers. Most computers don't have 128 bit builtin integers, so it's kind of unavoidable to split it up.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

dude i was planing on doing that the floating point was just to see how i could resolve a sientific notation to a normal figur .. but that doesn't work so .. i found an other way .. dw but tnx for the tip just have to figur out some way to reformat that funny looking format some of it makes sence some of it doesn't .. ill find out sooner or later i always do ;)
XplaiN but think of me as stupid
Locked