Floating Point Precision Loss


Posted on 16th Feb 2014 07:03 pm by admin

I'm writing a program to draw a three-dimensional cube (with a corner cut off) without using any 3D graphics APIs. The only API call I make is win32's SetPixel()

Everything is going great. I've drawn lines, faces, and even the entire cube. Then rotation came along.

Did you know?Explore Trending and Topic pages for more stories like this.
For some reason, when I rotate my cube, it begins to shrink. I became confused, then I realised something. Floating point numbers are truncated.

Here's some code that is fired everytime the user presses 'X' on the keyboard.

Code: p->setY( p->getY() * cos(5.0/180.0*PI) - p->getZ() * sin(5.0/180.0*PI)); p->setZ( p->getY() * sin(5.0/180.0*PI) + p->getZ() * cos(5.0/180.0*PI));

p is a Point object that I created. Here the Y value and the Z value of the Point are being set. The problem is everytime X is pressed, and this code is fired, a small amount of precision is lost. As a result, the cube shrinks.

I'm really completely stumped. I remember when studying assembler that floating point numbers can be truncated or rounded. I think rounding would solve my problem. Since 50% of the time the value would round up, and 50% of the time the value would round down.

Whereas with truncation values are always lost, and never gained.
No comments posted yet

Your Answer:

Login to answer
213 Like 53 Dislike
Previous forums Next forums
Other forums

distinct rows
Hi
version 10.2.0.3

I have a query output something like the following

ID

PHP Surveys
I really would like some advice.

If you have a client come to you asking for a survey to be d

login and redirect
hello! can someone help me.. can you give me an idea.. I want to make a login page and redirects it

How to have a log of all the status a VIM document had been ?
Hi guys,

I’m using SAP Invoice Management plugin and the /OPT/VIM_ANALYTICS transa

array & querys help/advice.
Ok so here goes , I have a mysql database and basically here's what I need to do.

// foreach

getting Vars to pass to next page.
Hello all,
I have a confusing situation on my hands, i am a member of a gaming community and we

Is it a good practice to store user info. in sessions?
I am making a user class for my script which stores all the user information in sessions. It takes u

Material xxx does not exist in plant xxx
Dear All,

I am working for a steel project which is repetitive manufacturing.

Mail Script Problems
I have created a PHP mail script. I am having a problem though. In $body i am trying to put two va

using file_get_contents??
okay how would i create a script using file_get_contents() in php have it grab search pages 1-20 and

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash