473,382 Members | 1,442 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,382 software developers and data experts.

floating-point precision

Hi guys,

I use LUTs to accelerate certain parts of my app. The LUTs contain
float numbers, and I generated the numbers very precisely, up to 10
decimals. All seems fine, however, when I printf the numbers in the
LUT, I do not get the same exact numbers. The first 6 decimals are ok,
but it got beserk after that. To illustrate further:

float myLUT = [0.123456789, 0.123456789, 0.123456789, ................] ;

printf("myLUT: .10f", myLUT[1]);

##### output

myLUT: 0.123456111
I am not quite sure why that is the case, although I believe float do
not have enough precision, so the compiler (VC 8) gives the closest
approximation that can be had with float. Is that so? Can somebody
enlighten me on that issue?

Thanks in advance,
Enrique

Mar 15 '07 #1
6 2467
Enrique Cruiz <jn*************@jetable.orgwrites:
I use LUTs to accelerate certain parts of my app. The LUTs contain
float numbers, and I generated the numbers very precisely, up to 10
decimals. All seems fine, however, when I printf the numbers in the
LUT, I do not get the same exact numbers. The first 6 decimals are ok,
but it got beserk after that. To illustrate further:

float myLUT = [0.123456789, 0.123456789, 0.123456789, ................] ;
float is only guaranteed to have 6 decimal digits worth of
accuracy. If you need more, use double, which has at least 10
decimal digits worth of accuracy. Also, read what the C FAQ has
to say about floating point numbers.
--
Peter Seebach on C99:
"[F]or the most part, features were added, not removed. This sounds
great until you try to carry a full-sized printout of the standard
around for a day."
Mar 15 '07 #2
Enrique Cruiz <jn*************@jetable.orgwrites:
I use LUTs to accelerate certain parts of my app. The LUTs contain
float numbers, and I generated the numbers very precisely, up to 10
decimals. All seems fine, however, when I printf the numbers in the
LUT, I do not get the same exact numbers. The first 6 decimals are ok,
but it got beserk after that. To illustrate further:

float myLUT = [0.123456789, 0.123456789, 0.123456789, ................] ;

printf("myLUT: .10f", myLUT[1]);
What the heck is a "LUT", and what language are you using? ("LookUp
Table", maybe?) The above is a syntax error in C, even if you replace
the "................" with something meaningful. It's probably some
compiler-specific extension.

Aside from that, type float just doesn't provide the precision you
need. Type double or long double might. Consult your system's
documentation.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 16 '07 #3
On Mar 15, 5:18 pm, Enrique Cruiz <jni6l03mdo6n...@jetable.orgwrote:
Hi guys,

I use LUTs to accelerate certain parts of my app. The LUTs contain
float numbers, and I generated the numbers very precisely, up to 10
decimals. All seems fine, however, when I printf the numbers in the
LUT, I do not get the same exact numbers. The first 6 decimals are ok,
but it got beserk after that. To illustrate further:

float myLUT = [0.123456789, 0.123456789, 0.123456789, ................] ;

printf("myLUT: .10f", myLUT[1]);

##### output

myLUT: 0.123456111

I am not quite sure why that is the case, although I believe float do
not have enough precision,
Why? Float is only guaranteed to have 6 digits of precision, which
is exactly what you are seeing.

If you need more than 6 digits of precision, then, use double
(And unless you have a reason to use float, use double).

Why do you think you need this precision? (Are you trying
to check the results using the LUT against those not
using a LUT?)

Have you checked to see if using the LUT actually does
increase execution speed? (It is quite possible for
the opposite to happen). Have you checked whether
the putative incease in speed is significant?

- William Hughes

Mar 16 '07 #4
Enrique Cruiz wrote:
>
I use LUTs to accelerate certain parts of my app. The LUTs contain
float numbers, and I generated the numbers very precisely, up to 10
decimals. All seems fine, however, when I printf the numbers in the
LUT, I do not get the same exact numbers. The first 6 decimals are
ok, but it got beserk after that. To illustrate further:

float myLUT = [0.123456789, 0.123456789, 0.123456789, ..........] ;

printf("myLUT: .10f", myLUT[1]);

##### output

myLUT: 0.123456111

I am not quite sure why that is the case, although I believe float
do not have enough precision, so the compiler (VC 8) gives the
closest approximation that can be had with float. Is that so? Can
somebody enlighten me on that issue?
Look in <float.hfor the number of digits available. Consider
using double rather than float.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
mm
--
Posted via a free Usenet account from http://www.teranews.com

Mar 16 '07 #5
William Hughes wrote:
>
.... snip ...
>
Have you checked to see if using the LUT actually does increase
execution speed? (It is quite possible for the opposite to
happen). Have you checked whether the putative incease in speed
is significant?
What is a LUT? A capitalized abbreviation for a lute, perhaps. If
so, who is playing it.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 16 '07 #6
CBFalconer <cb********@yahoo.comwrites:
What is a LUT?
Look-Up Table.
--
"I should killfile you where you stand, worthless human." --Kaz
Mar 16 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George Hester | last post by:
At the time this suggestion was made I didn't have the wherewithall to even attempt it. But over time I learned enough to make a stab at it. Let just say the foating DIV had to provide the same...
3
by: JHR | last post by:
Hey all, I'm trying to make a sidebar box float to the right of various items, and for those items to wrap if a user shrinks his browser window. Instead, in every browser I've tried except for...
12
by: meltedown | last post by:
I would like the floating divs to float and then the header to come after them , on the left. That's what I thought clearing the floats was for, but in this example, the header is to the right of...
1
by: buliwyf_23 | last post by:
I have this: CSize sz; sz.cx = dwOutX1; sz.cy = dwOutY1; CPoint pt(sz); ClientToScreen(&pt);
6
by: Usenet | last post by:
I might be being silly here. On my links page I've got a whole load of floating boxes, which I'm really pleased with. But then I want the footer to be *below* them. On my current site...
1
by: hendrakieran | last post by:
Hi Guys, I'd like to get some help regarding creating a floating window with the following scenario: * I have index.html which is contains the frameset definition: <html> <head> </head>
2
by: Qiang | last post by:
Those who have used Google notebook may notice that google notebook displays the notes in a small floating window of the browser. I have tried to create a similar floating window, but with no luck....
0
by: gdrenfrew | last post by:
I'd like to know if it is possible to stop the parent application of a floating form becoming active when the controls on the floating form are clicked? I've got a large application, with multiple...
2
by: murali.desikan | last post by:
Hi, The definition of floating literal in the C++ (ISO/IEC 14882:2003) grammar is as follows (Note: I have replaced the "opt" subscript used in the standard with to indicate optional symbol)....
6
by: Jeremy | last post by:
I've got a floating div which becomes visible when a link is clicked. I want the div to be hidden when the user clicks anywhere on the page except for whithin the div. What is the best way to do...
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...
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.