Re: lingo-l Getting separate parts of a number
Carl West wrote: ... splitList = [[integer(pVal+[.5,-.5][1+(pVal0)]),pVal-integer(pVal+[.5,-.5][1+(pVal0)])],[0,0]][1+(pVal=0)] Oh never mind, Colin's answer can be made into one line and it beats the pants off us: splitList = [bitor(pVal,0),pVal- bitor(pVal,0)] 4x faster than mine which was 1.5x faster than Pedja's -- Carl West mailto:[EMAIL PROTECTED] http://carl.west.home.comcast.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
RE: lingo-l Getting separate parts of a number
I agree:) What's next? I have so much work to do I need something else to keep my mind off it. BTW...nice code Carl -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Carl West Sent: 03 September 2004 07:43 To: [EMAIL PROTECTED] Subject: Re: lingo-l Getting separate parts of a number Carl West wrote: ... splitList = [[integer(pVal+[.5,-.5][1+(pVal0)]),pVal-integer(pVal+[.5,-.5][1+(pVal 0)])],[0,0]][1+(pVal=0)] Oh never mind, Colin's answer can be made into one line and it beats the pants off us: splitList = [bitor(pVal,0),pVal- bitor(pVal,0)] 4x faster than mine which was 1.5x faster than Pedja's -- Carl West mailto:[EMAIL PROTECTED] http://carl.west.home.comcast.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!] [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
A more traditional way, just using abs and some math, gives you: intPart =integer(abs(myFloat) - 0.5) * (-1 + (((myFloat + abs(myFloat)) / (myFloat * 2))*2)) floatPart =abs(myFloat) - abs(intPart) It's the same as my original posting, but abs'ing everything to get the numbers, and that second part of the intPart equation is to restore the sign to its proper place. - Tab [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
convert to a string, set the delimeter to a period, grab the last chunk and convertint it back to float and save to add back on That sounds like a lot more work than my two lines. [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
This is all you need: intPart =integer(myFloat - .5) floatPart =myFloat - intPart - Tab At 10:32 PM 9/1/04, John Waller wrote: Hi, I have a floating point number, e.g. 45.6200, and I want to be able to store the whole number part and the fraction part separately, so that I can increment an integer value and keep the remainder (the fraction part) to be added on to a later increment value. Does anyone know if there are any lingo commands for doing any of this - or have any ideas how else I might do this? Maybe I could convert to a string and search for decimal point and extract numbers before that etc. but this seems a bit long winded. Thanks in advance, John [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!] [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
Tab Julius wrote: This is all you need: intPart =integer(myFloat - .5) floatPart =myFloat - intPart Unless myFloat is negative. It's the whole rounding-up/-down/truncating thread again. With a twist. At 10:32 PM 9/1/04, John Waller wrote: Hi, I have a floating point number, e.g. 45.6200, and I want to be able to store the whole number part and the fraction part separately,... -- Carl West mailto:[EMAIL PROTECTED] http://carl.west.home.comcast.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
At 11:46 AM -0400 9/2/04, Troy Rollins wrote: I was hoping to see you get it to one line though. Sounds like a challenge: anArray = string(float).split(.) That's pseudo ActionScript! [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
On Sep 2, 2004, at 2:39 PM, Colin Holgate wrote: anArray = string(float).split(.) That's pseudo ActionScript! Does that not actually leave out some steps though? I don't know of any Lingo split function. You'd need to instantiate an object, etc. to get access to that method, no? -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
At 2:47 PM -0400 9/2/04, Troy Rollins wrote: I don't know of any Lingo split function. You'd need to instantiate an object, etc. to get access to that method, no? Don't let reality get in the way. [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
RE: lingo-l Getting separate parts of a number
For Christ sake...it's a single liner people!:))) pVal = 1234.90899 splitList = [value(string(pVal).char[1..(offset(.,string(pVal)))-1]),value(string( pVal).char[(offset(.,string(pVal)))..string(pVal).char.count])] put splitList Covert the pVal to a string first and it gets even faster...just joking..it's crap code but it's in a single line:) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Troy Rollins Sent: 02 September 2004 19:47 To: [EMAIL PROTECTED] Subject: Re: lingo-l Getting separate parts of a number On Sep 2, 2004, at 2:39 PM, Colin Holgate wrote: anArray = string(float).split(.) That's pseudo ActionScript! Does that not actually leave out some steps though? I don't know of any Lingo split function. You'd need to instantiate an object, etc. to get access to that method, no? -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!] [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
On Sep 2, 2004, at 4:18 PM, Pedja wrote: For Christ sake...it's a single liner people!:))) pVal = 1234.90899 splitList = [value(string(pVal).char[1..(offset(.,string(pVal))) -1]),value(string( pVal).char[(offset(.,string(pVal)))..string(pVal).char.count])] put splitList Nice. Hideous, but nice. I had this - pVal = 1234.90899 testArray = (PRegEx_Split([string(pVal)], \.) But note that it only gives a list of strings representing the numbers. -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
RE: lingo-l Getting separate parts of a number
Damn...I've got it now with maths(ish)! It's a single liner and works with both positive and negative numbers correctly. pVal = -18267.8932 splitList = [integer((abs(pVal)-(abs(pVal) - integer(abs(pVal)-0.5)))* integer(getNormalized(vector(pVal,0,0))[1])),(abs(pVal) - integer(abs(pVal)-0.5)) * integer(getNormalized(vector(pVal,0,0))[1])] put splitList -- [-18267, -0.8932] I've just done a quick test and this approach is 9.5 times faster than the string approach...I've checked on 200 iterations. Without the vector math it gets 15.5 times faster but that was the only way I could determine if the number is positive or negative without an if statement:))) If someone knows an easier mathematical method to get the positive/negative value let me know as this is something that is bugging me for a long time and I bloody do intend to use it! cheerio -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Carl West Sent: 02 September 2004 20:14 To: [EMAIL PROTECTED] Subject: Re: lingo-l Getting separate parts of a number Troy Rollins wrote: On Sep 2, 2004, at 7:42 AM, Colin Holgate wrote: convert to a string, set the delimeter to a period, grab the last chunk and convertint it back to float and save to add back on That sounds like a lot more work than my two lines. Yep. So it my offset routine. Any routine that coerces the number to text, processes the text and coerces it back to a number is going to be pretty darn slow relative to manipulating the number as a number. If you're only doing it every now and then, it's probably not a problem. If you're doing it a lot, streamline it. -- Carl West mailto:[EMAIL PROTECTED] http://carl.west.home.comcast.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!] [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
On Sep 2, 2004, at 5:18 PM, Pedja wrote: pVal = -18267.8932 splitList = [integer((abs(pVal)-(abs(pVal) - integer(abs(pVal)-0.5)))* integer(getNormalized(vector(pVal,0,0))[1])),(abs(pVal) - integer(abs(pVal)-0.5)) * integer(getNormalized(vector(pVal,0,0))[1])] put splitList -- [-18267, -0.8932] Just when things couldn't get any uglier... vector math. ;-) Well done! -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
RE: lingo-l Getting separate parts of a number
Okidoki...don't like my vectors!? You've asked for it..here's a refined version and 2x faster then with vectors:) pVal = -18267.8932 splitList = [integer((abs(pVal)-(abs(pVal) - integer(abs(pVal)-0.5* (pVal/sqrt(power(pVal,2))),(abs(pVal) - integer(abs(pVal)-0.5))* (pVal/sqrt(power(pVal,2)))] put splitList If you can make it better just with bloody Lingo let me know... -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Troy Rollins Sent: 02 September 2004 22:24 To: [EMAIL PROTECTED] Subject: Re: lingo-l Getting separate parts of a number On Sep 2, 2004, at 5:18 PM, Pedja wrote: pVal = -18267.8932 splitList = [integer((abs(pVal)-(abs(pVal) - integer(abs(pVal)-0.5)))* integer(getNormalized(vector(pVal,0,0))[1])),(abs(pVal) - integer(abs(pVal)-0.5)) * integer(getNormalized(vector(pVal,0,0))[1])] put splitList -- [-18267, -0.8932] Just when things couldn't get any uglier... vector math. ;-) Well done! -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!] [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
RE: lingo-l Getting separate parts of a number
Forgot to include a fail safe for zero value. pVal = -7852.8932 splitList = [integer((abs(pVal)-(abs(pVal) - integer(abs(pVal)-0.5* (pVal+0.1)/(sqrt(power(pVal+0.1,2))),(abs(pVal) - integer(abs(pVal)-0.5))* (pVal+0.1)/(sqrt(power(pVal+0.1,2)))] It will return [-1.,1.] if you feed it with 0 [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
On Sep 2, 2004, at 7:50 PM, Pedja wrote: Okidoki...don't like my vectors!? You've asked for it..here's a refined version and 2x faster then with vectors:) pVal = -18267.8932 splitList = [integer((abs(pVal)-(abs(pVal) - integer(abs(pVal)-0.5* (pVal/sqrt(power(pVal,2))),(abs(pVal) - integer(abs(pVal)-0.5))* (pVal/sqrt(power(pVal,2)))] put splitList If you can make it better just with bloody Lingo let me know... Nope. You kicked it. I still kind of like the Preg_ex approach for the simplicity, but I don't doubt the parenthetical power of your lingo-based solution. -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
Pedja wrote: Damn...I've got it now with maths(ish)! It's a single liner and works with both positive and negative numbers correctly. pVal = -18267.8932 splitList = [integer((abs(pVal)-(abs(pVal) - integer(abs(pVal)-0.5)))* integer(getNormalized(vector(pVal,0,0))[1])),(abs(pVal) - integer(abs(pVal)-0.5)) * integer(getNormalized(vector(pVal,0,0))[1])] put splitList -- [-18267, -0.8932] I've just done a quick test and this approach is 9.5 times faster than the string approach...I've checked on 200 iterations. Without the vector math it gets 15.5 times faster but that was the only way I could determine if the number is positive or negative without an if statement:))) If someone knows an easier mathematical method to get the positive/negative value let me know as this is something that is bugging me for a long time and I bloody do intend to use it! Try this, it uses the 'if'-less 'if' of lists*. splitList = [integer([pVal+[.5,-.5][1+(pVal0)],0][1+(pVal=0)]),pVal-integer([pVal+[.5,-.5][1+(pVal0)],0][1+(pVal=0)])] It would be shorter if I could ignore the special case of zero: splitList = [integer(pVal+[.5,-.5][1+(pVal0)]),pVal-integer(pVal+[.5,-.5][1+(pVal0)])] * With care you can even make it a 'case'-less 'case'. Ick. I'd hate to have to de-bug this kind of code. -- Carl West mailto:[EMAIL PROTECTED] http://carl.west.home.comcast.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
On Sep 3, 2004, at 1:19 AM, Carl West wrote: I'd hate to have to de-bug this kind of code. No doubt. Great fun as list-code, but in reality a few short concise lines is preferable for real work. Still, nice lingo-flexing you guys. -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
lingo-l Getting separate parts of a number
Hi, I have a floating point number, e.g. 45.6200, and I want to be able to store the whole number part and the fraction part separately, so that I can increment an integer value and keep the remainder (the fraction part) to be added on to a later increment value. Does anyone know if there are any lingo commands for doing any of this - or have any ideas how else I might do this? Maybe I could convert to a string and search for decimal point and extract numbers before that etc. but this seems a bit long winded. Thanks in advance, John [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
On Sep 1, 2004, at 10:32 PM, John Waller wrote: Maybe I could convert to a string and search for decimal point and extract numbers before that etc. but this seems a bit long winded. Convert it to a string and use offset to locate the decimal point. May sound long-winded, but should be a pretty straightforward function to build. -- Troy RPSystems, Ltd. http://www.rpsystems.net [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
There are probably various ways to cheat this. Here's one: afloat = 12.34567 wholenumber = bitor(afloat,0) fraction = afloat-wholenumber put wholenumber fraction -- 12 0.3457 [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
Re: lingo-l Getting separate parts of a number
convert to a string, set the delimeter to a period, grab the last chunk and convertint it back to float and save to add back on Colin Holgate wrote: There are probably various ways to cheat this. Here's one: afloat = 12.34567 wholenumber = bitor(afloat,0) fraction = afloat-wholenumber put wholenumber fraction -- 12 0.3457 [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!] [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]