Redimension error

Hi I'm trying to implement a simple version of the 'linspace' function from Matlab, but it doesn't work due to strange behavior in the Redimension command.

Function linspace2(destWave,X1,X2,DeltaEx)
    Wave destWave
    Variable X1,X2,DeltaEx
   
    Variable NumPts= abs((X2-X1)/DeltaEx)+1
    Redimension/N=(NumPts) destWave
    destWave = ( (X2-X1)/(NumPts-1) )*p + X1    
   
End


If I type
make/O junk
linspace2(junk,.1,.45,.05) ; print junk


I get 7 points, even though there should be 8:
junk[0]= {0.1,0.15,0.2,0.25,0.3,0.35,0.4}


Curiously, if I move the decimal point by a factor of 10 in all parameters, the behavior is correct:
linspace2(junk,1,4.5,.5) ; print junk
junk[0]= {1,1.5,2,2.5,3,3.5,4,4.5}


I'm going a little crazy looking for an error in my math--what is this caused by? From printing out 'numpnts(destWave)', etc., within the function, both before and after the call, it seems like the Redimension function is just not working.

This behavior was seen in both Igor 6 and Igor 7 on a Macbook, and also on a Windows PC running Igor 6.

Thanks,

Jeff
Change this:
Variable NumPts= abs((X2-X1)/DeltaEx)+1


to this:

Variable NumPts= abs((X2-X1)/DeltaEx)+1
Print/D NumPts, trunc(NumPts), ceil(NumPts)


Now execute this:
make/O junk
linspace2(junk,.1,.45,.05)


It prints: 8, 7, 8.

This means that (abs((X2-X1)/DeltaEx)+1" is very close to 8.0 but not quite. Floating point math has finite precision.

Also Print, even Print/D has limits to its precision.

Depending on your goal, use trunc, round or ceil in calculating NumPts.