As a mental challenge I wrote a prog
to calculate permutations i.e. the number
of possible sets of unique numbers in a
larger set of numbers.
The formula involves factorial calculations
i.e. factorial 10 is 10 x 9 x 8 x 7 ..... x 2 x 1.
The numbers get BIG as you can imagine.
Try factorial 99 (99!) on your calculator
and see how far you get.
Rev hits the limit at around 200 so instead of
using an "int" one would normally go for a "long".
But (and I don't regard this as a deficiency) Rev
doesn't seem to have one or a way to use
"scientific" notation.
This was a problem way back (before Win, perhaps
before you were born) when "micro-computers" were
limited to 640k memory less what the OS needed.
One of the techniques I recall was called "scaling" and
involved dividing the numbers by a factor which moved
the decimal point to the left so that the available slots
to the right of the decimal point were used.
The trick was deciding the divisor so as to not cause
an overflow and loss of accuracy.
Does anyone have any info. on the "capacity" of Rev
when dealing with large numbers and/or scaling?
Had a quick look in the Rev help without any luck.
Permutations - and BIG numbers
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Permutations - and BIG numbers
Life is just a bowl of cherries.
Maybe the format function might help you.
From the docs:
put format("%1.3e",865.3) -- returns 8.653e+02, scientific notation
on mouseUp pMouseBtnNo
local tValue
put 1 into tValue
repeat with i=1 to 99
put i*tValue into tValue
end repeat
put format("%1.3e",tValue)&cr&tValue
end mouseUp
Hope that helps,
Malte
From the docs:
put format("%1.3e",865.3) -- returns 8.653e+02, scientific notation
on mouseUp pMouseBtnNo
local tValue
put 1 into tValue
repeat with i=1 to 99
put i*tValue into tValue
end repeat
put format("%1.3e",tValue)&cr&tValue
end mouseUp
Hope that helps,
Malte
Permutations - and BIG numbers
Malte
This line
put i*tValue into tValue
give a "range overflow" error
as before with big values (c.200)
since the number is still an int
at this stage.
Did think of using the "format"
when the numbers are input
but at small values the scientific
notation will produce inaccurate
results.
Can't recall if a big number in
scientific notation can be multiplied
by an int. or not. Will give it a try
when time allows.
Have to look for info and try the
"scaling" trick.
This line
put i*tValue into tValue
give a "range overflow" error
as before with big values (c.200)
since the number is still an int
at this stage.
Did think of using the "format"
when the numbers are input
but at small values the scientific
notation will produce inaccurate
results.
Can't recall if a big number in
scientific notation can be multiplied
by an int. or not. Will give it a try
when time allows.
Have to look for info and try the
"scaling" trick.
Life is just a bowl of cherries.