Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

upper array bound 1

Status
Not open for further replies.

Tracey

Programmer
Oct 16, 2000
690
NZ
Hi there

I have inherited a complex javascript calculator. Part of this project tests values by using constant "bands" which hold range values.

Code:
function FillBandingLimits(){
	BandingLimits=new Array(7);
	BandingLimits[0]=[0.00,15.5];
	BandingLimits[1]=[15.5,16.5];
	BandingLimits[2]=[16.5,17.5];
	BandingLimits[3]=[17.5,18.5];
	BandingLimits[4]=[18.5,19.5];
	BandingLimits[5]=[19.5,20.5];
	BandingLimits[6]=[20.5,21.5];
}

I am to add some functionality in a similar fashion, only they have given me specs like :
band 1 will be greater than 2.5.
band 2 will be 2 - 2.5
band 3 will be 1.7 - 2
Band 4 is less than 1.7

so my question is this: How can I declare one of these bands with 2.5 as a lower bound and infinity as an upper? or negative infinity as a lower bound? Is this even possible?

cheers in advance [cheers]

Tracey

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
I don't think it's in the definition of the bands that you will need to be careful with your functionality... it's where you use them.

I'm not quite sure what a "band" is, but if you simply create a band like:

BandingLimits[7]=[2.5,-99];

...and then, wherever you check the upper limit of the bound against some input, you can just program it so that the test for the upper limit always passes if the bandinglimit is set to -99.

Or: For positive infinity, do the [2.5, -99] thing. For negative infinity, just have one element to the array (for example: [2.5]). Programatically, you can decide that the absence of a second element means that NO LOWER LIMIT exists and the other element MUST BE an upper limit.

Does this make sense? Does it help?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Possibly use Number.MAX_VALUE in place of positive infinity and Number.MIN_VALUE in place of negative infinity. These values are not the same as infinity, but there will not be any larger or smaller values in a Javascript application.

 
Hey there Dave

Well I tried your suggestion:
Code:
function FillTZIHayConBandLimits(){
	//Hayward Conventional
	TZIBandingLimits=new Array(4);
	TZIBandingLimits[0]=[2.5,Number.MAX_VALUE];
	TZIBandingLimits[1]=[2.0,2.5];
	TZIBandingLimits[2]=[1.7,2.0];
	TZIBandingLimits[3]=[Number.MIN_VALUE,1.7];

}
but when i check for which band i need for a value of -49.44 I am returned TZIBandingLimits[0]
Code:
for(j=0; j<TZIBandingLimits.length; j++) {
	//Check the sample value against bands.  Display band number relevent to this value
	if (TZI >= TZIBandingLimits[j][0] && TZI < TZIBandingLimits[j][1]){
	    window.document.getElementById("lblTZIBand").value = j+1;
	}//if
}//for



Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
oh it seems to be working (mysteriously) now

forget my last and thanks

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
*sigh*
no, forget my last last. It works well for all except the negative values. Must remember to do proper comprehensive testing before posting...

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Just experimenting with it, it seems to be choking on Number.MIN_VALUE being large enough to compare the value to. It works fine if you hard code a number in (I used negative and positive 2 billion), though. I made it a bit more object-oriented with the following:
Code:
var TZIBandingLimits=new Array(), ti=0;

//Hayward Conventional
TZIBandingLimits[ti++]={min:2.5,max:2000000000};
TZIBandingLimits[ti++]={min:2.0,max:2.5};
TZIBandingLimits[ti++]={min:1.7,max:2.0};
TZIBandingLimits[ti++]={min:-2000000000,max:1.7};

function FillTZIHayConBandLimits(TZI)
{
for(var j=0; j<TZIBandingLimits.length; j++)
  {
  if (TZI >= TZIBandingLimits[j].min && TZI < TZIBandingLimits[j].max)
    {
    window.document.getElementById("lblTZIBand").value = j+1;
    break;
    }//if
  }//for
}

Lee
 
no worries, i just put -99 in there and all is sweet. I am told not to expect -ve values for real data anyway :)

thanks for the tip

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top