473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

casting to int and floor(float) difference

27
Hi all

Is there any other difference except return type between

(int)a and floor(a) ?

a is float type variable

Thanks
Sep 24 '06 #1
1 3169
D_C
293 100+
I think the reason for having two of them is because floats can deal with bigger numbers. However, now that I think about it, if the number is big enough, there should be no need to take the floor, since it's already chopped off because there isn't enough precision.

In that case it must be for smaller numbers. For any float with a negative exponent, it is completely cleared away. For an exponent with at most (Precision-1) bits, it will clear bits. Start from the LSB, and while the exponent is negative, clear the bit. Each time you move left, increment the exponent by 1.
Sep 24 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Seabook | last post by:
Hello guys, I just bumped into a page at nVidia.com that says that casting from float to int using (int) is a bad idea. What is the problem with (int)? Is it just speed or some other sublime bug...
6
by: Nobody | last post by:
How does one round a float? ie... 4.4 returns 4, while 4.5 returns 5. I see the floor and ceiling functions, but that floor would take 4.4 and return 4 and ceiling would return 5. I guess I could...
5
by: Thierry | last post by:
Hello, I'd like to write a function who return a float with only two digits after the point. For instance : 12.34567 -> 12.34 Any help would be welcome Tkx, Titi.
6
by: James Thurley | last post by:
According to the docs, floats are 32 bit and doubles are 64 bit. So using floats should be faster than using doubles on a 32 bit processor, and my tests confirm this. However, most of the Math...
2
by: Tom Larard | last post by:
Hi, We have an app which uses the latest version of perl DBI and DBD::Pg to execute a query, using placeholders. It fails to cast the float I send into a number and generates the following...
8
by: David Williams | last post by:
Hi all, I have a templated Vector3D class which holds (x,y,z) components as the specified type. I quite often wish to cast a Vector3D holding ints into a Vector3D holding floats and vice versa....
17
by: sophia.agnes | last post by:
Hi , I was going through peter van der linden's book Expert C programming, in this book there is a section named "How and why to cast" the author then says as follows (float) 3 - it's a...
3
by: DWilli3501 | last post by:
I have two short programs that use floating point numbers. The first gives an incorrect result. By simply placing a "cout" (or any executable line) in the correct location of the program I get a...
0
by: Michael Rudolph | last post by:
Hi DB2 newsgroup, I have encountered a difference between our development DB2 on Windows and the test environment on AIX. If using the LOCATE scalar function with a SMALLINT as LENGTH parameter...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.