# Traps and explanations when comparing non-integer types (floating-point, fixed-point) using Pascal

**URL:** <https://forum.castle-engine.io/t/traps-and-explanations-when-comparing-non-integer-types-floating-point-fixed-point-using-pascal/1464>\
**Category:** News\
**Created:** [December 14, 2024, 10:55am UTC](https://forum.castle-engine.io/t/traps-and-explanations-when-comparing-non-integer-types-floating-point-fixed-point-using-pascal/1464 "2024-12-14T10:55:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [December 14, 2024, 10:55am UTC](https://forum.castle-engine.io/t/traps-and-explanations-when-comparing-non-integer-types-floating-point-fixed-point-using-pascal/1464/1 "2024-12-14T10:55:04Z")

</div>

| [![Floating castle from https://sketchfab.com/3d-models/floating-castle-1e157bab3a4042eb834ca07d73aa28ce by Shahriar Shahrabi](https://forum.castle-engine.io/uploads/default/original/2X/8/8e758bd53e8a373f430d5b0f6b1255ff81e5fe67.png)](https://castle-engine.io/wp/wp-content/uploads/2024/12/scene_0.png "Floating castle from https://sketchfab.com/3d-models/floating-castle-1e157bab3a4042eb834ca07d73aa28ce by Shahriar Shahrabi") |

  
Recently I got a very nice question about comparing non-integer values in Pascal (thank you to _Jacek Mulawka_!).

The core of the question was: Does the condition below (`if`) evaluate to `true` or `false`, and why?

```
MyVar := 0.1;
if MyVar = 0.1 then
  Writeln('Yes, MyVar equals 0.1')
else
  Writeln('No, MyVar does not equal 0.1');

```

I created a testcase for this (compiles with both FPC and Delphi) and I provided a lengthy explanation what happens and why in this repository:

[How does comparing “MyVar = 0.1” work for different types](https://github.com/michaliskambi/test-float-compare/)?

As you can read there, it’s actually quite complex what happens, and depends on both the type, and compiler, and “platform” (_“platform”_ is a term I tend to use to mean _“combination of operating system and the processor, OS / CPU”_). The short version of the conclusion is: use `Math.SameValue` to compare non-integers, but I explain much more details (and justified exceptions to this simplified conclusion) in the linked repo, so please read it 🙂

I hope that this overview is helpful to everyone dealing with floats, in Pascal or otherwise 🙂

P.S. The screen attached to this post continues our tradition _“if you don’t have anything relevant to show, post something pretty rendered using our engine”_. This is a [floating castle from Sketchfab](https://sketchfab.com/3d-models/floating-castle-1e157bab3a4042eb834ca07d73aa28ce) created by [Shahriar Shahrabi](https://sketchfab.com/shahriyarshahrabi) and rendered in our [Castle Model Viewer](https://castle-engine.io/castle-model-viewer).

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [December 28, 2024, 1:37pm UTC](https://forum.castle-engine.io/t/traps-and-explanations-when-comparing-non-integer-types-floating-point-fixed-point-using-pascal/1464/2 "2024-12-28T13:37:31Z")

</div>

Listed on December 28, 2024, 1:37pm UTC


