287 operator <> (const z1, z2: hwFloat) z : boolean; inline; |
309 operator <> (const z1, z2: hwFloat) z : boolean; inline; |
288 begin |
310 begin |
289 z:= (z1.isNegative <> z2.isNegative) or (z1.Frac <> z2.Frac) or (z1.Round <> z2.Round); |
311 z:= (z1.isNegative <> z2.isNegative) or (z1.Frac <> z2.Frac) or (z1.Round <> z2.Round); |
290 end; |
312 end; |
291 |
313 |
292 operator + (const z1, z2: hwFloat) z : hwFloat; |
314 operator + (const z1, z2: hwFloat) z : hwFloat; inline; |
293 begin |
315 begin |
294 if z1.isNegative = z2.isNegative then |
316 if z1.isNegative = z2.isNegative then |
295 begin |
317 begin |
296 // z.QWordValue:= z1.QWordValue + z2.QWordValue |
|
297 z:= z1; |
318 z:= z1; |
298 z.Frac:= z.Frac + z2.Frac; |
319 z.Frac:= z.Frac + z2.Frac; |
299 z.Round:= z.Round + z2.Round; |
320 z.Round:= z.Round + z2.Round; |
300 if z.Frac<z1.Frac then inc(z.Round) |
321 if z.Frac<z1.Frac then inc(z.Round) |
301 end |
322 end |
302 else |
323 else |
303 // if z1.QWordValue > z2.QWordValue then |
|
304 if (z1.Round > z2.Round) or ((z1.Round = z2.Round) and (z1.Frac > z2.Frac)) then |
324 if (z1.Round > z2.Round) or ((z1.Round = z2.Round) and (z1.Frac > z2.Frac)) then |
305 begin |
325 begin |
306 z.isNegative:= z1.isNegative; |
326 z.isNegative:= z1.isNegative; |
307 // z.QWordValue:= z1.QWordValue - z2.QWordValue |
|
308 z.Round:= z1.Round - z2.Round; |
327 z.Round:= z1.Round - z2.Round; |
309 z.Frac:= z1.Frac - z2.Frac; |
328 z.Frac:= z1.Frac - z2.Frac; |
310 if z2.Frac > z1.Frac then dec(z.Round) |
329 if z2.Frac > z1.Frac then dec(z.Round) |
311 end |
330 end |
312 else |
331 else |
313 begin |
332 begin |
314 z.isNegative:= z2.isNegative; |
333 z.isNegative:= z2.isNegative; |
315 // z.QWordValue:= z2.QWordValue - z1.QWordValue |
|
316 z.Round:= z2.Round - z1.Round; |
334 z.Round:= z2.Round - z1.Round; |
317 z.Frac:= z2.Frac-z1.Frac; |
335 z.Frac:= z2.Frac-z1.Frac; |
318 if z2.Frac < z1.Frac then dec(z.Round) |
336 if z2.Frac < z1.Frac then dec(z.Round) |
319 end |
337 end |
320 end; |
338 end; |
321 |
339 |
322 operator - (const z1, z2: hwFloat) z : hwFloat; |
340 operator - (const z1, z2: hwFloat) z : hwFloat; inline; |
323 begin |
341 begin |
324 if z1.isNegative = z2.isNegative then |
342 if z1.isNegative = z2.isNegative then |
325 // if z1.QWordValue > z2.QWordValue then |
|
326 if (z1.Round > z2.Round) or ((z1.Round = z2.Round) and (z1.Frac > z2.Frac)) then |
343 if (z1.Round > z2.Round) or ((z1.Round = z2.Round) and (z1.Frac > z2.Frac)) then |
327 begin |
344 begin |
328 z.isNegative:= z1.isNegative; |
345 z.isNegative:= z1.isNegative; |
329 // z.QWordValue:= z1.QWordValue - z2.QWordValue |
|
330 z.Round:= z1.Round - z2.Round; |
346 z.Round:= z1.Round - z2.Round; |
331 z.Frac:= z1.Frac-z2.Frac; |
347 z.Frac:= z1.Frac-z2.Frac; |
332 if z2.Frac > z1.Frac then dec(z.Round) |
348 if z2.Frac > z1.Frac then dec(z.Round) |
333 end |
349 end |
334 else |
350 else |
335 begin |
351 begin |
336 z.isNegative:= not z2.isNegative; |
352 z.isNegative:= not z2.isNegative; |
337 // z.QWordValue:= z2.QWordValue - z1.QWordValue |
|
338 z.Round:= z2.Round - z1.Round; |
353 z.Round:= z2.Round - z1.Round; |
339 z.Frac:= z2.Frac-z1.Frac; |
354 z.Frac:= z2.Frac-z1.Frac; |
340 if z2.Frac < z1.Frac then dec(z.Round) |
355 if z2.Frac < z1.Frac then dec(z.Round) |
341 end |
356 end |
342 else |
357 else |
343 begin |
358 begin |
344 // z.QWordValue:= z1.QWordValue + z2.QWordValue |
|
345 z:= z1; |
359 z:= z1; |
346 z.Frac:= z.Frac + z2.Frac; |
360 z.Frac:= z.Frac + z2.Frac; |
347 z.Round:= z.Round + z2.Round; |
361 z.Round:= z.Round + z2.Round; |
348 if z.Frac<z1.Frac then inc(z.Round) |
362 if z.Frac<z1.Frac then inc(z.Round) |
349 end |
363 end |
350 end; |
364 end; |
351 |
365 |
|
366 operator < (const z1, z2: hwFloat) b : boolean; inline; |
|
367 begin |
|
368 if z1.isNegative xor z2.isNegative then |
|
369 b:= z1.isNegative |
|
370 else |
|
371 (* Not so sure this specialcase is a win w/ Round/Frac. have to do more tests anyway. |
|
372 if (z1.Round = z2.Round and (z1.Frac = z2.Frac)) then |
|
373 b:= false |
|
374 else *) |
|
375 b:= ((z1.Round < z2.Round) or ((z1.Round = z2.Round) and (z1.Frac < z2.Frac))) <> z1.isNegative |
|
376 end; |
|
377 |
|
378 operator > (const z1, z2: hwFloat) b : boolean; inline; |
|
379 begin |
|
380 if z1.isNegative xor z2.isNegative then |
|
381 b:= z2.isNegative |
|
382 else |
|
383 (* |
|
384 if z1.QWordValue = z2.QWordValue then |
|
385 b:= false |
|
386 else*) |
|
387 b:= ((z1.Round > z2.Round) or ((z1.Round = z2.Round) and (z1.Frac > z2.Frac))) <> z1.isNegative |
|
388 end; |
|
389 |
352 function isZero(const z: hwFloat): boolean; inline; |
390 function isZero(const z: hwFloat): boolean; inline; |
353 begin |
391 begin |
354 isZero := z.Round = 0 and z.Frac = 0; |
392 isZero := z.Round = 0 and z.Frac = 0; |
355 end; |
393 end; |
356 {$ENDIF} |
394 {$ENDIF} |
357 |
395 |
358 operator - (const z1: hwFloat) z : hwFloat; |
396 operator - (const z1: hwFloat) z : hwFloat; inline; |
359 begin |
397 begin |
360 z:= z1; |
398 z:= z1; |
361 z.isNegative:= not z.isNegative |
399 z.isNegative:= not z.isNegative |
362 end; |
400 end; |
363 |
401 |
364 |
402 |
365 operator * (const z1, z2: hwFloat) z : hwFloat; |
403 operator * (const z1, z2: hwFloat) z : hwFloat; inline; |
366 begin |
404 begin |
367 z.isNegative:= z1.isNegative xor z2.isNegative; |
405 z.isNegative:= z1.isNegative xor z2.isNegative; |
368 z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32); |
406 z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32); |
369 z.Round:= z.Round + QWord(z1.Round) * z2.Round; |
407 z.Round:= z.Round + QWord(z1.Round) * z2.Round; |
370 end; |
408 end; |
371 |
409 |
372 operator * (const z1: hwFloat; const z2: LongInt) z : hwFloat; |
410 operator * (const z1: hwFloat; const z2: LongInt) z : hwFloat; inline; |
373 begin |
411 begin |
374 z.isNegative:= z1.isNegative xor (z2 < 0); |
412 z.isNegative:= z1.isNegative xor (z2 < 0); |
375 z.QWordValue:= z1.QWordValue * abs(z2) |
413 z.QWordValue:= z1.QWordValue * abs(z2) |
376 end; |
414 end; |
377 |
415 |
378 operator / (const z1: hwFloat; z2: hwFloat) z : hwFloat; |
416 operator / (const z1: hwFloat; z2: hwFloat) z : hwFloat; inline; |
379 var t: hwFloat; |
417 var t: hwFloat; |
380 begin |
418 begin |
381 z.isNegative:= z1.isNegative xor z2.isNegative; |
419 z.isNegative:= z1.isNegative xor z2.isNegative; |
382 z.Round:= z1.QWordValue div z2.QWordValue; |
420 z.Round:= z1.QWordValue div z2.QWordValue; |
383 t:= z1 - z2 * z.Round; |
421 t:= z1 - z2 * z.Round; |