Code center > Darwinbots3

Make v3 support decimals

(1/4) > >>

Botsareus:
also will make v3 support desimals in the stack and the following commands:
round ' round to n desimal places
ipart 'integer part
fpart 'fraction part
^ ' to the power of
50 * 'memory location at 50
int 'same as in vb
fix 'same as in vb
nl 'natural log nl(10^3) / nl(10) = 3
e 'nl(e) = 1  e = 2.718...
pi = 3.142...
sin
cos
tan
atn 'reverse of tan


--- Quote ---1. Floating point errors are a pain to debug.
--- End quote ---

Not really , I will use int or round or fix when ever nessisary, and the only trouble will be divide, but even then I can just write:

--- Quote ---a b div
--- End quote ---
if b < 1/32000 then 32000 = ans

Numsgil:
For starters, read this FAQ articles 15 through 18.  Properly using floating point numbers is a delicate art, and I don't have the skill to create a robust DNA system from it.  If someone wants to create a system on paper for dealing with floats, I'll consider maybe moving to a floating point system, but probably not.


Second, read the command list, and the rest of the post.  How do I know you haven't?

1.  sin and atan already exist.
2.  32000 isn't a special number in the new system.  The new "magic" number is 9999 (that's 4 nines, ie: you get 4 digits of precision in base 10 when storing in robot DNA).

Last, if anyone could ever come up with a gene that was seriously impossible to do without floating point math, I would also reconsider floating point numbers.  Note, though, that with 9 digits of precision on the stack, you can implement your own fixed point math.  Just multiply all your "fractions" by like 100 or 1000.

Botsareus:
Numsgil I found a compromize. I will post it within  the next 2 weeks.

bacillus:
Isn't it already possible to emulate a floating point stack for small numbers? All you have to do is scale it up by, say, 100, and then before you use it divide by 100. This way, at least, you can get a higher accuracy for division operations.

Numsgil:
What you describe is called "fixed point" (as opposed to floating point).  It is indeed already possible, but it is a little cumbersome.  I could maybe be convinced to work towards a system that automagically handles the multiply and division that comes along with fixed point math, if people have an interest.

Navigation

[0] Message Index

[#] Next page

Go to full version