[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

replacing a formula from a string

Josselin

11/8/2006 1:55:00 PM

I have a long formula expressed as a string

formula_1 = "6366.00 * Math.acos(Math.cos(self.latitude) *
Math.cos(latitude) * Math.cos(longitude -self.longitude) +
(Math.sin(self.latitude) * Math.sin(LatitudeRad)) )"

I need to use it in the preparation of some SQL query conditions like :

condition += (c(:villes){ 6366.00 * Math.acos(Math.cos(self.latitude) *
Math.cos(latitude) * Math.cos(longitude -self.longitude) +
(Math.sin(self.latitude) * Math.sin(LatitudeRad)) ) < distance } )

How could I write it only once 'formula_1' and reuse it like :
condition += (c(:villes){ formula_1 < distance }) # this is wrong as
formula_1 is a string ..

thansk for your suggestions

joss

2 Answers

Paul Lutus

11/9/2006 7:33:00 AM

0

Josselin wrote:

> I have a long formula expressed as a string
>
> formula_1 = "6366.00 * Math.acos(Math.cos(self.latitude) *
> Math.cos(latitude) * Math.cos(longitude -self.longitude) +
> (Math.sin(self.latitude) * Math.sin(LatitudeRad)) )"
>
> I need to use it in the preparation of some SQL query conditions like :
>
> condition += (c(:villes){ 6366.00 * Math.acos(Math.cos(self.latitude) *
> Math.cos(latitude) * Math.cos(longitude -self.longitude) +
> (Math.sin(self.latitude) * Math.sin(LatitudeRad)) ) < distance } )
>
> How could I write it only once 'formula_1' and reuse it like :
> condition += (c(:villes){ formula_1 < distance }) # this is wrong as
> formula_1 is a string ..

The simplest way to solve this problem is to convert your equation into a
function. Why are you not doing this? Does the equation change regularly?

If there are as many equations as database records, then of course you want
to think up a way to interpret the equations as you encounter them. But if
there is one equation and many sets of variables to apply to it, then
rewrite the text form of your equation as a function. Then read the
database records, convert the values to numerics, and submit them to the
function.

Put simply, it's called "computer programming".

From this:

> formula_1 = "6366.00 * Math.acos(Math.cos(self.latitude) *
> Math.cos(latitude) * Math.cos(longitude -self.longitude) +
> (Math.sin(self.latitude) * Math.sin(LatitudeRad)) )"

to this (not tested):

function formula_1(latitude,longitude,latitude_rad)
return 6366.0 * math.acos(@latitude) * Math.cos(latitude) *
Math.cos(longitude - @longitude) + (Math.sin(@latitude) *
Math.sin(latitude_rad)))
end

--
Paul Lutus
http://www.ara...

Jim D. in TN

11/6/2010 4:01:00 AM

0

On Nov 4, 5:15 pm, "cody chunn" <cchu...@comcast.net> wrote:
> Some EMs that had moving targets would continue to move after game over. I
> guess that motion could be considered the first attract mode.

I believe as with most pinball feature firsts, the first attract
feature (you can't call it a mode) was on a mid-1930's game. It was
flashing backglass lights. I just read about it on an old flyer a
week or two ago but now I can't recall what game.