BigDecimal vs floating points...
Hi all,
I know its probably been asked amillion times before but I need to finally fully understand and get my head around the two.
Firstly here are some bits I've been told by different people and read in different places (alot of people seem to think differently which is what confuses me):
- I've read that if you are wanting precision for currency for example that floating point shouldnt be used because of its accuracy down to the fact it cant represent every decimal number.
- The some people have told me that it doesnt matter and theres not much point ,ost the time in BigDecimal all you need to do is correct the floating point with formatting.
- I've asked about this before but people just seem to give me a short answer to it but without actually explaining why or where they get it from, you cant just assume an answer based on nothing...
I'm building some engineering software that has a general accuracy of 3 decmial places (millimeters from meters) and my first thought is that if currency at 2 decimal places requires BigDecimal then I surely require it (I cant afford to be missing off mm for every calculation, theres alot!) but the problem is this has resulted in me building pretty much the whole application with BigDecimal which you can probably imagine brings up thoughts about performance and memory uptake, I do calculations with BigDecimal, store data in BigDecimal and infact the only thing I do in double is the graphical display as the accuracy isnt so important.
My last question is if this is an ok way to build an accurate application it makes me start to wonder why is floating points used more than BigDecimals, surely most numbers are required to be accurate in applications especially of an enterprise scale?
Thanks,
Ken
MarksmanKen wrote:
So your a big user of BigDecimal as well then? Thats good to know someone else thinks in similar ways, I was starting to feel like abit of an idiot for using them so extensively lolNot at all. The idiots are the people who use primitives rather than BigDecimal "because they're faster" even though they've never actually experienced any performance problems. Of course, there are lots of cases where the speed of a primitive is preferable, but on the whole those guys know perfectly well who they are and what they're doing.
My program is very calculation heavy and I've not had any real performance issues yet but I was wondering if the performance gain would be significant enough while keeping the accuracy.Testing will show you the way. Don't let any "we tested this calculation a million times using primitives and the same one using BigDecimal, and it showed a remarkable 3 seconds quicker using primitives" sidetrack you, either. All that matters is that your actual production code is performant enough for your application. Generally speaking, anything involving currency will probably be better using BigDecimal, or, really, a Money class which happens to use BigDecimal under the covers. Quite why enterprise-targeted languages don't have some sort of native Money or Currency class out-of-the-box remains a mystery, to be honest.
Similar Messages
-
Hi everybody,
This line:
System.out.println((0.1+0.7)*10);outputs 7.999999999999999
This is due to how floating point numbers are stored. When writing
a code, sometimes it behaves in an intended way, sometimes it doesn't
(like the one above). Is there a way to "predict" when the code is ok and
when isn't ? Are there any tips to be aware of to get around that kind
of problems ?
Cheers,
AdrianNo. Using BigDecimal just because you don't understand how floating-point numbers work would be... um... short-sighted. And it wouldn't help, either. As soon as you divide 1 by 3 then you have to know how decimal numbers work, which is essentially the same problem.
Edit: I forgot the forum hasn't been automated to provide the mandatory link for people who ask this question. We still have to do it by hand.
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Edited by: DrClap on Oct 11, 2007 3:02 PM -
Error on floating point?
One can expect that 1.2 * 3.0 equals 3.60
But the following statement has the result: 3.5999999999999996
- System.out.println(1.2 * 3.0);
Why?
How can I control or estimate the floating point error?
Thanks in advance!It is not a Java problem or a Java error. It is inherent to floating-point arithmetic.
1.2 can not be exactly represented in binary floating-point arithmetic. But 1.25 (that is 5 * (2 ^ -2)) can be.
If your problem requires exact decimal arithmetic, use BigDecimal instead. (It is very slow compared to the conventional floating-point arithmetic).
Please consult a textbook on numerical calculus for the techniques of dealing with floating-point error - it depends on the algorithm that you use for solving your problem. -
Easiest way to split a floating point value
Hello, I am trying to split a floating-point value (double) into its fractional and integer parts? I have been trying to find some sort of method in BigDecimal or Double that would do it but so far I haven't come up with anything. I know it could be done by searching through it as a String but that sounds like a very inefficent way to do it. I would appreciate any help you could give. Thanks
float f;
int i = (int) f;
float frac = f-i; -
SQL Loader and Floating Point Numbers
Hi
I have a problem loading floating point numbers using SQL Loader. If the number has more than 8 significant digits SQL Loader rounds the number i.e. 1100000.69 becomes 1100000.7. The CTL file looks as follows
LOAD DATA
INFILE '../data/test.csv' "str X'0A'"
BADFILE '../bad/test.bad'
APPEND
INTO TABLE test
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
Amount CHAR
and the data file as follows
"100.15 "
"100100.57 "
"1100000.69 "
"-2000000.33"
"-100000.43 "
the table defined as follows
CREATE TABLE test
Amount number(15,4)
) TABLESPACE NNUT050M1;
after loading a select returns the following
100.15
100100.57
1100000.7
-2000000
-100000.4
Thanks in advance
RussellActually if you format the field to display as (say) 999,999,999.99, you will see the correct numbers loaded via SQL Loader.
null -
R6002 - floating point not loaded / C++ Runtime Error
Good Evening,
I have been having this problem with Adobe Bridge for a while and tonight sat down to try and solve it. Fresh version of Windows XP reinstalled all programs and this is still happening! Any Ideas?
This error only occurs with Adobe Bridge, I can load Photoshop etc.. all fine.
Error:
"Runtime Error!
Program: C:\ProgramFiles\Adobe\Adobe Bridge CS3\Bridge.exe
R6002
- floating point not loaded"
Here is a print screen..
http://images.unbrokenphotography.co.uk/BridgeError.jpgIs there are answer to this problem? This error message is appearing on an entire lab full of computers. We are running Web Premium CS4
I have tried to reset the Bridge Preferences:
Hold down the Ctrl key and click on Bridge icon to start.
Should get a reset window with 3 options.
Choose the first option
I still get "Runtime Error! Program: C:\Prgram Files\Adobe\Adobe Bridge CS4\Bridge.exe R6002 -floating point support not loaded" -
I have one Captivate 3 project published as a Stand Alone
project with Flash 8 selected. There are 36 slides, no audio, no
eLearning, SWF size and quality are high.
One person who runs this gets an "Invalid Floating Point"
error when he tries to run it the first time. He is running Windows
XP SP2, Firefox 3.0.4. and Flash Player 10.0.12.36. Other Captivate
projects I've created run fine for him. This one sometimes runs
after the first Error message.
Any thoughts on the cause and fix?
Thanks,
JanetiMediaTouch probably doesn't support Floating Point formats - it certainly doesn't mention them in the advertising. Try saving your files as 24-bit PCMs, and they should import fine.
-
Pack and Floating Point Data Type in ABAP
Dear All,
I am new to ABAP. Started with data types. Came across pack and floating point.
Please let me know what PACK and Floating Point stands for with few examples and the main difference between them.
Regards
Arun VHi,
You'd better ask this question in ABAP forum http://forums.sdn.sap.com/forum.jspa?forumID=50 .
Best Regards,
Ada -
Conversion of a floating point type field
Hi,
I'm fetching field ATFLV from table AUSP for a particular value of ATINN.ATFLV is a floating point type field.
Can anyone please guide me as to how to convert this field(ATFLV) from floating point no. to a simple no.?
Helpful answers will be rewarded.
Regards,
Siprahi,
Do like this,
float f = 234.33;
int i = (int) f; // i has value 234.
reward points if helpful.. -
Maximum size of a floating-point number
Morning all,
Does anyone know what the maximum size of a floating point number can be under Solaris 8 running on
a V880?
Regards,
Richard BreckonI'm not sure what you're asking.
The maximum size is 128 bits.
The maximum value is as given in /usr/include/float.h: 1.189731495357231765085759326628007016E+4932L -
Hello All,
I am having some trouble checking the value of a field with Key Figure type Number with 8 byte floating point. I want to read that field and populate another field with an X if true. For example if that field is equal to 5,0000000000000000E+07 then i want to mark the other field with an 'X'.
The problem is in my code, how do i read that number in the fltp field, such as the number above. my code reads as follows for the 'X' field.
if SOURCE_FIELDS-abc123 eq 5000000.
RESULT = 'X'.
endif.
Thanks everyone in advanceYou don't need to worry about converting the code into standard format or floating, just implement your code as you want and it will automatically take care of the conversion. Basically 5,0000000000000000E+07 = 50,000,000.
thanks.
Wond -
Hello,
Running FCP 5.1
Having audio sync issues and was double checking my settings.
Although the sequence presets are at 16 bit, they are showing up in the browser as 32bit Floating Point.
Any thoughts?
I generally capture now at 30 minute increments and actually have always had this issue. FCP 4.5 and 5.1
all settings are where they should be.
although I do notice, obviously when the device is off, the audio output defaults to 'default' not to firewire dv.
thanks
iMac intel Mac OS X (10.4.8)Some more details please. What hardware device are you sourcing the audio clips from? The likely culprit is your capture settings. What preset are you using? Check Audio/Video Settings-Capture Presets and see if the preset you've selected records audio as 32 bit. It will say in the right column after you've selected your preset.
If it says 32 bit there, click Edit to get the Capture Preset Editor. Under Quicktime Audio Settings, the Format field should give you a selection of sample rates and possibly alternate bit depths. If your only choice is 32 bit, (as it is for me when I capture audio via my RME, 32 bit Integer in my case) then you'd be well served by bringing those files into Peak or Quicktime and saving them as 16 bit Integer files to match your sequence settings.
If you've imported these files into FCP from an audio editor that can create 32 bit floating point audio files, eg Kyma, Sequoia, Nuendo, etc. then the same advice applies. The 32 bit files are much larger than they need to be and may upset the apple cart (he he, pun) when pulled into a sequence with different settings. More cpu overhead for sure.
Let us know what you find. -
How to make floating point division
I have tried many alternatives but i couldnt make any single floating point number printed to a page...
I am compiling the servlet with eclipse 3.2 without any error but the jsp page says java.lang.NoSuchFieldError: floatnumber even i have that variable...
i have tried double,float but both of them makes the error above...but i can print long as well.
can anyone teach me to divide 2 integer values and print the exact result like;
3 / 5 = 0.6can anyone teach me to divide 2 integer values and
print the exact result like;
3 / 5 = 0.6
int a= 3, b= 5;
double result= ((double)a)/b;... or any valid variation thereof.
kind regards,
Jos -
Reading Floating Point PLC5 Registers Kills my ability to write to any register
When ever I create an object that reads a PLC5 Floating Point Register(F8:5),it kills my ability to write to any other PLC register. The problem only shows up with Floating Point registers. If I use integer registers (N7:121 etc.)I can read/write fine. It also severely slows down my normal driver scan update time. Even though it is set to scan every 30 seconds, I may only get an update every few minutes. Anyone else ever run into this? Thanks in advance!
Hi,
It might be helpful creating a log file to monitor com port activity.
Here's the Knowledgebase article about it.
http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/cac576863ff648a186256b5900794761?OpenDocument
Another way to check the serial port activity would be using "portmon"
software available at
http://www.sysinternals.com/ntw2k/freeware/portmon.shtml
I hope this helps.
Remzi A.
Applications Engineering
National Instruments -
Cannot get Oracle 10g to start on a G5. Floating point exception
After a very painful 10g (EE) installation process i.e fixing all the following:
1) Created the missing /opt directory
2) Installation of XCode 1.2
3) Fixing the root.sh file
4) Downloaded the crstl file provided by Ron
5) Copied /etc/oratab/oratab to /etc/oratab
I tried bringing up the Oracle 10g instance by logging onto Sql*Plus as sysdba and running
startup nomount pfile ='/Users/oracle/admin/db01/scripts/init.ora''. The instance comes up for a few socunds and crashes. This is what i get in the alert.log
==========================================================
Sat Jul 17 11:40:08 2004
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 2
KCCDEBUG_LEVEL = 0
Using LOG_ARCHIVE_DEST_10 parameter default value as USE_DB_RECOVERY_FILE_DEST
Autotune of undo retention is turned on.
Dynamic strands is set to TRUE
Running with 2 shared and 18 private strand(s). Zero-copy redo is FALSE
IMODE=BR
ILAT =18
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up ORACLE RDBMS Version: 10.1.0.3.0.
System parameters with non-default values:
processes = 150
sga_target = 146800640
control_files = /Users/oracle/oradata/db01/control01.ctl, /Users/oracle/oradata/db01/control02.ctl, /Users/oracle/oradata/db01/control03.ctl
db_block_size = 8192
compatible = 10.1.0.2.0
db_file_multiblock_read_count= 16
db_recovery_file_dest = /Users/oracle/flash_recovery_area
db_recovery_file_dest_size= 2147483648
undo_management = AUTO
undo_tablespace = UNDOTBS1
remote_login_passwordfile= EXCLUSIVE
db_domain =
dispatchers = (PROTOCOL=TCP) (SERVICE=db01XDB)
job_queue_processes = 10
background_dump_dest = /Users/oracle/admin/db01/bdump
user_dump_dest = /Users/oracle/admin/db01/udump
core_dump_dest = /Users/oracle/admin/db01/cdump
db_name = db01
open_cursors = 300
pga_aggregate_target = 16777216
PMON started with pid=2, OS id=4037
MMAN started with pid=3, OS id=4039
DBW0 started with pid=4, OS id=4041
LGWR started with pid=5, OS id=4043
CKPT started with pid=6, OS id=4045
SMON started with pid=7, OS id=4047
RECO started with pid=8, OS id=4049
Sat Jul 17 11:40:16 2004
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
CJQ0 started with pid=9, OS id=4051
Sat Jul 17 11:40:16 2004
starting up 1 shared server(s) ...
Sat Jul 17 11:40:18 2004
Errors in file /Users/oracle/admin/db01/bdump/db01_ckpt_4045.trc:
ORA-07445: exception encountered: core dump [semop+8] [SIGFPE] [Invalid floating point operation] [0xA0004CE4] [] []
Sat Jul 17 11:40:19 2004
Errors in file /Users/oracle/admin/db01/bdump/db01_mman_4039.trc:
ORA-07445: exception encountered: core dump [semop+8] [SIGFPE] [Invalid floating point operation] [0x41EDB3C] [] []
Sat Jul 17 11:40:21 2004
Errors in file /Users/oracle/admin/db01/bdump/db01_pmon_4037.trc:
ORA-00822: MMAN process terminated with error
Sat Jul 17 11:40:21 2004
PMON: terminating instance due to error 822
Instance terminated by PMON, pid = 4037
==========================================================
Any idea on what needs to be done to fix this error. I remember that i had the very same issue with the Oracle 9i R2 Developers release.
Any help will be greatly appreciated.After a very painful 10g (EE) installation process
i.e fixing all the following:<snip>
Sat Jul 17 11:40:19 2004
Errors in file
/Users/oracle/admin/db01/bdump/db01_mman_4039.trc:
ORA-07445: exception encountered: core dump [semop+8]
[SIGFPE] [Invalid floating point operation]
[0x41EDB3C] [] []
Sat Jul 17 11:40:21 2004
Errors in file
/Users/oracle/admin/db01/bdump/db01_pmon_4037.trc:
ORA-00822: MMAN process terminated with error
Sat Jul 17 11:40:21 2004
PMON: terminating instance due to error 822
Instance terminated by PMON, pid = 4037==============================================> Any idea on what needs to be done to fix this error.
I remember that i had the very same issue with the
Oracle 9i R2 Developers release.
Any help will be greatly appreciated.You mentioned the 9ir2 release. Do you still have any reference to the 9ir2 software in your environment ? With a little luck you have, and in that case it not so hard to find a solution ...
Ronald.
http://homepage.mac.com/ik_zelf/oracle
Maybe you are looking for
-
Airplay failure after using Apple TV.
The setup is a MacBook Pro, Apple TV and Airport Express. When I reboot my MacBook both Apple TV and Airplay works. If I Connect to the Apple TV and disconnect again, my Airplay icon disappears. When rebooting again, everything works again. Does some
-
Rasterizing smart objects, 3 methods?
Hi folks. There are 3 ways to rasterize a smart object. With the smart object selected in the layers palette: 1) Layer > Rasterize > Layer 2) Layer > Rasterize > Smart Object 3) Layer > Smart Objects > Rasterize There is of course a 4th possibility d
-
Adobe Interactive Forms in CE 7.1.1
Hi guys, I just downloaded the sneak preview of CE 7.1.1 on SDN. I'm planning to install it very soon. Actually, at my work, we have SAP ECC 6.0 running only on the ABAP stack. Can I connect my ECC 6.0 ABAP to the CE 7.1.1 ADS for my form rendering,
-
There are a lot of examples in the WIKI .. please search for the same Dear All. i have no experiance with ABAP but i want to learn the ABAP which is used in BW in tranformation or routines, i have never use abap can any body tell me the links or eboo
-
Since security update 2008-007 version 1.0 that I just installed today, ichat has stopped working. I can't even see the preferences menu item to try to change to port 443 as a test I saw suggested in another topic on this forum. What can I do? Should