Does C++ Do points in math?

so I was testing with c++ and I noticed that it didn't work with points like 1.3 would equal 1.

is this normal or did I do something wrong?

Update:

thank you llaffer

Comments

  • you are using integers instead of floats.

    So instead of using "int" as your data type, use "double".

  • Yes, but only if you make it. :P

    A lot of arithmetic in C++ is done with ints (or variations thereof, such as chars, shorts or longs), which are designed to represent integers only. For instance, when you divide two ints, the remainder is thrown away (so 100/50 is 2, but 100/51 is only 1, and 100/101 is 0, and so on).

    If you require easy-to-use numbers that keep the decimal components, you would usually use something like float or double. double has a wider range and greater accuracy than float, but it takes twice as much memory and (on some machines) more processor time to work with. However, note that float and double do not have perfect precision, and so some operations you do with them will come out slightly 'off'.

    If you need a number that keeps the decimal component but also has perfect accuracy, unfortunately there is no default data type that provides this. You would have to make your own data structure to manage the appropriate logic, and it would run more slowly than standard integer or floating-point arithmetic.

Sign In or Register to comment.