274 hwAbs.isNegative:= false |
274 hwAbs.isNegative:= false |
275 end; |
275 end; |
276 |
276 |
277 function hwSqr(const t: hwFloat): hwFloat; |
277 function hwSqr(const t: hwFloat): hwFloat; |
278 begin |
278 begin |
279 hwSqr:= t * t |
279 hwSqr.isNegative:=false; |
|
280 hwSqr.QWordValue:= QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32); |
|
281 hwSqr.Round:= hwSqr.Round + QWord(t.Round) * t.Round |
280 end; |
282 end; |
281 |
283 |
282 function hwSqrt(const t: hwFloat): hwFloat; |
284 function hwSqrt(const t: hwFloat): hwFloat; |
|
285 var l, r: QWord; |
|
286 c: hwFloat; |
283 begin |
287 begin |
284 hwSqrt.isNegative:= false; |
288 hwSqrt.isNegative:= false; |
285 hwSqrt.QWordValue:= Round(sqrt(1.0 / $100000000 * (t.QWordValue)) * $100000000) |
289 l:= 0; |
|
290 r:= t.QWordValue div 2 + 1; |
|
291 repeat |
|
292 c.QWordValue:= (l + r) div 2; |
|
293 if hwSqr(c).QWordValue > t.QWordValue then r:= c.QWordValue else l:= c.QWordValue |
|
294 until r - l <= 1; |
|
295 hwSqrt.QWordValue:= l |
286 end; |
296 end; |
287 |
297 |
288 function Distance(const dx, dy: hwFloat): hwFloat; |
298 function Distance(const dx, dy: hwFloat): hwFloat; |
289 var x, y: hwFloat; |
299 begin |
290 Result: hwFloat; |
300 Distance:= hwSqrt(hwSqr(dx) + hwSqr(dy)) |
291 begin |
|
292 x:= dx * dx; |
|
293 y:= dy * dy; |
|
294 Result:= x + y; |
|
295 Result.QWordValue:= Round(sqrt(1.0 / $100000000 * (Result.QWordValue)) * $100000000); |
|
296 Distance:= Result |
|
297 end; |
301 end; |
298 |
302 |
299 function DistanceI(const dx, dy: LongInt): hwFloat; |
303 function DistanceI(const dx, dy: LongInt): hwFloat; |
300 begin |
304 begin |
301 DistanceI:= Distance(int2hwFloat(dx), int2hwFloat(dy)) |
305 DistanceI:= Distance(int2hwFloat(dx), int2hwFloat(dy)) |