Trig etc functions on fractions?

Fraction.java with trig methods?
I've been playing with geospatial stuff for a while now, and I've been striking a lot of problems with the inherent inaccuracies of floating point number representations, especially in complex-calculated values.
Here's a simple but pertinent example:
class TheSumOfSevenSevethsIsNotOne
  public static void main(String[] args) {
    double f = 1.0/7.0;
    double sum = 0.0;
    for (int i=0; i<7; i++) {
      sum += f;
    System.out.println("sum = "+sum);
// OUTPUT:
// sum = 0.9999999999999998
// not 1 as you might expectThe numbers I'm storing are latitudes and longitudes in degrees, so the max_value is just 360, but the requirement is that lat/lon must be accurate to 9 decimal places, which equates to about +/- 0.6 millimetres, which is (apparently) close enough to be regarded as "millimetre accuracy" by cartographers, even though total ambiguity is 1.2 mm.
So three digits, plus six digits, is only nine digits, right?... and the humble int can store a tad more than 9 digits...
                                 123.123 456
Integer.MAX_VALUE = (2^31)-1 = 2,147,483,647So I got to thinking... How would it be if I stored all lat/lons in the database as integers (multiplied by a million)? and did all my calculations rounded (not truncated) to the nearest 1. I could even save a few hundred million bytes that way... But that still leaves the same ole ambiguity around the actual calculations, many of which involve division ;-(.
So I got to thinking maybe I could use fractions? How would a Fraction.java look?
I googled around and found some great stuff, including:<ul>
<li>[Diane Kramers Fraction.java|http://aleph0.clarku.edu/~djoyce/cs101/Resources/Fraction.java]
<li>[Working with Fractions in Java|http://www.merriampark.com/fractions.htm] (includes BigFraction.java - very handy)
<li>[Doug Leas Fraction.java|http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/misc/Fraction.java]
</ul>
But I haven't found anything which implements the basic trigonometry functions like sin, cos, tan, cot (and whatever else)... but [Daves Short Trig Course|http://www.clarku.edu/~djoyce/trig/] might give me the understanding required to do so... nor does any existing Fraction.java (which I've found so far) implement handy things like x^y, log, modulo (and whatever else) ... and not being a mathematician myself, I'm not overly eager to implement them... I'd never be sure I'd done the job properly.
Please is anyone aware of any such implementations, even partial ones? Or could someone perhaps be persuaded to do part(s) of it just for the challenge?
Cheers all. Keith.

Sir Turing Pest,
I do geospatial stuff amost exclusively and I dont understand this post.
Why not just use doubles? The "error" you're seeing is so trivial.
Put into perspective, if you were positioning something from the
Sun to Pluto you'd be off by half a millimeter.
How do you figure that you only need 9 digits?
ignore 360 degrees. the circumference of the earth is 41k km and you need
accuracy to .6 mm = 11 places
(40 075.02 kilometers) / (.5 millimeters) = 80,150,040,000I didn't figure it, our local GIS expert did, based mainly on the size of an integer,
When I do the math I get to 9 decimal places == about 1.11 mm, and that's allways rounded (not truncated) to 9 decimal places which I think means our points are accurate to plus or minus about 0.6 mm.... but I'm just a humble computer programmer, NOT a mathemetician or a geospatial expert.
We're storing lat/lon to 9 decimal places... So 1 is 1 degree.
               40,075.160000000     kilometers     circumference of the earth
equals     40,075,160.000000000     meters        circumference of the earth
equals        111,319.888888889     meters        meters per degree at the equator
equals              0.000000001     degrees         storage accurracy
equals              0.000111320     meters         
equals              1.113198889     millemeters     storage accurracy in millimeters
So sure you established that aggregate double addition comes out "wrong".
Then dont do it, lol. Dont waste your time trying to invent new number
storage. Just try to write your algorithms so you don't do aggregate addition as much.We try not to aggregate calculated values... but there are certain algorithms, like the reverse/mercator transforms where it's unavoidable... So opportunities for improvement is this area a likely to be NOT very cost effective, ie: bigger than Ben Hur, harder than a bulls azz, and uglier than an extreme closeup of my scotum... My main concern has been (rightly or wrongly) the inherent inaccuracy in our storage of numbers.... thinking that improvements in this area just might be cost-effective, and therefore doable.
Iterestingly... we had a tree-clearing case kicked out of court recenctly because we couldn't define the boundaries of the national park in question to the satisfaction of the court... a "satisfaction level" which was based on our own "millimeter accuracy" definition of the required accuracy of survey data, which is based on international standards for GIS. ie: It's a bit of sore spot around the office at the moment, and I'm trying to do some bluddy thing about it... I'm just at a bit of a loss as to exactly what, without throwing literally millions of dollars at the problem to upgrade ALL our systems to 11 decimal places (or better). I'm in stress city.
Cheers. Keith.

Similar Messages

  • T61 cd/dvd audio,burning etc. functions no longer perform.

    When I place a CD or DVD into the laptop I can hear the DVD multi working but the default Windows Media Player does not respond. All other computer functions OK. Whats up?  Thanks, MDO

    Is DLA enabled on your drive?  I've seen that cause some pretty strange problems.
    Right click on the drive icon and look for a DLA tab.
    Z.
    The large print: please read the Community Participation Rules before posting. Include as much information as possible: model, machine type, operating system, and a descriptive subject line. Do not include personal information: serial number, telephone number, email address, etc.  The fine print: I do not work for, nor do I speak for Lenovo. Unsolicited private messages will be ignored. ... GeezBlog
    English Community   Deutsche Community   Comunidad en Español   Русскоязычное Сообщество

  • TOOL access to fscript (Partition, MakeAppDist etc)functions?

    G'day All
    Does anyone know how to access fscript functionality from within TOOL code?
    I mean not the usual execute command then run fscript -i somefile.fsc but
    true agent access within tool. I need the usual commands used to partition a
    project, like FindPlan, SetProjType, FindActEnv, Partition 3, NewPart,
    MoveServiceToPart, AssignAppComp, UnassignAppComp, MakeAppDist etc.
    At the moment I have automated VMS scripts that generate specific temp.fsc
    (fscript) files for me that then run like "ftscipt -i buildappABC.fsc". I
    like to do so from within TOOL.
    Many Thanks,
    Dirk
    Dirk Haben
    Fort&eacute; System Administrator
    Sealcorp Holdings Limited
    Level 38 Central Park, 152 St George's Terrace, Perth, WA 6000
    e-mail: Dirk.Habensealcorp.com.au
    phone: +61-8-9265-5758
    ================================================================================================
    IMPORTANT INFORMATION
    This message and any files transmitted with it are confidential and should be read only by those
    persons to whom it is addressed.
    If you have received this message in error, please notify us immediately by way of reply. Please
    also destroy and delete the message from your computer. Any unauthorised form of reproduction
    of this message is strictly prohibited.
    It is the duty of the recipient to virus scan and otherwise test the information provided before
    loading onto any computer system.
    SEALCORP does not warrant that the information is free of a virus or any other defect or error.
    SEALCORP is not liable for the proper and complete transmission of the information contained in
    this communication, nor for any delay in its receipt.
    Any views expressed in this message are those of the individual sender, except where the sender
    specifically states them to be the views of SEALCORP.
    ================================================================================================

    Hi,
    Please attach the project. I will check with internal build and let you know the outcome.

  • OnClick, onBlur, onChange etc function.

    I'v browsed many threads and found that (for example) 'HTML Form Element Attributes' people can fill out 'onClick, onBlur, onChange etc'. Actually what programming language is used to fill out this ? How many 'onXXX' functions out there ? Any documentation may help.
    Thanks.
    Gamez.

    Hi,
    what you are talking about are javascript event handlers. Since I'm German I have this quick overview for you: http://de.selfhtml.org/javascript/sprache/eventhandler.htm
    Maybe you can use it to search for those function names in the web.
    Greets

  • Fonts in "title space eg name, company phone etc" appera as fractions

    The fonts in Address book are fractions in all the space for titles "name, phone, fax, company etc." How can this be resolved. It happened after buying and installing Lion and finding out my CS3 software were not supported reinstall Snow Leopard.

    Use in InDesign DataMerge. You might save your Excel file in csv or tab seperated txt file.
    Mor details how to use it you will find in the online help: "Data Merge"

  • Error when I try to use the XMLElement(), XMLForest(), etc functions?

    I'm getting an "invalid column name" error when I try to use the xmlelement() function (and the like). Is this function only available on 9i Release 2? How do I find the SQLX functions and/or load them up for use? Hopefully someone will see this as a quick question and answer it for me!
    Cheers,
    Fish

    Reply
    Sorry. These are not loadable they are core database functionality only available with 9.2.0.1.0 and later..

  • Can Mobile Me users change to Lion without doing anything special?  For example, how will Calendars, Mail, etc. function if all are now synced with Mobile Me?

    Presently, our Mail, Calendars, etc. are being synced using Mobile Me accounts.  Considering all of the changes coming to Calendars, etc. with Lion, anything special to do before / during a change to Lion?

    Hi
    If you already have a Mobile Me account it will work with Lion until you change to iCloud or June 2012, which ever comes first...
    Calanders, Contacts, Mail, Notes will become part of iCloud when launched (in the very near future), your iDisk, Photo Gallery and iWeb hosting will cease when you register for iCloud or in June 2012. So if you use the features of Mobileme that will cease to be, carry on using Mobileme for as long as possible.
    http://www.apple.com/uk/icloud/what-is.html
    http://http://www.apple.com/uk/mobileme/transition.html
    Hope this helps.
    M. 

  • Why doesn't it work anymore?  I just paid for pfd to Excel, Word, etc function through Adobe...

    I'm signed in but the program asks me to sign in when I try to convert a file.  Then it asks me to pay again!  It was working fine for about an hour...then this snafu...

    [topic moved to Acrobat.com Services forum]

  • Illustror CC Alt-Shift (to duplicate and resize etc) functionality no longer working.

    Any help as to why this simple shortcut is suddenly not working in Illustrator CC?
    I try to use it to duplicate an empty circle with a coloured path while scaling it down (with the intention of using Ctrl D to continue the progression). The shortcut simple resizes the path without duplicating it. Please help.
    Many thanks,
    Paul.

    Did it ever work in that context?
    It works within the scale tool, but with the bounding box it scales to the center.

  • I can't load the add neighbours, send gifts etc function in a facebook game. I have avg, spywareblaster, spybot and windows defender running on my machine. please help

    Recently I updated all my anti spyware/malware software, and deleted all cookies and history. Since then I have been unable to load specific pages in the Gardens of Time Facebook game. I can play the game, but can't add neighbours, and send gifts. These pages should bring up lists of my current GOT friends, all my facebook friends and a recommended list of request recipients.

    Thanks for this mha007 - I can now open FF with a new profile. Can I copy my settings from the old profile or will this bring over the same problem, maybe a corrupt file. If it would bring the same problem, is there any way I can check which file is corrupt, apart from taking them over one by one?

  • How do I get back my edit functions, copy and paste, without doing a restore?

    When I switched to Firefox 4 I no longer have the file, edit, etc. functions anywhere. I can't or don't know how to copy and paste websites to emails for instance without the edit functions.

    I have checked the toolbar buttons and have MENU ticked, I went to the customize toolbar thing and added (by drag and drop) the cut copy and paste and other buttons I cant find now, and they showed up at first, then they disappeared. The top section seems terribly narrow now and I cant find any way to add the buttons underneath where they used to be...help!

  • Data dcitioany view and function and procedures insure a package

    I need the run a query on the Data dcitioany, to get a list of packages as well as a list for procedures and functions inside on Oracle 10g

    I use DBA_SOURCE,
    I used like this
      SELECT v.owner,
           (CASE V.type
            WHEN 'FUNCTION'  THEN NULL
            WHEN 'PROCEDURE' THEN NULL
            ELSE v.name
            END
           )PACKAGE_NAME ,
            UPPER(
            SUBSTR
            TRANSLATE(
            LTRIM(REPLACE(SUBSTR(ltrim(v.text),LENGTH('PROCEDURE')+1),'"',''),' '),
            '+++'
            ),---TEXT TO BE SEARCH
            1,---STARTING POSITION
            INSTR(
            TRANSLATE(
            LTRIM(REPLACE(SUBSTR(ltrim(v.text),LENGTH('PROCEDURE')+1),'"',''),' '),
            '+++'
            ||'+'
            '+'
            )-1 ---lENGTH
            )OBJECT_NAME
            TRIM(SUBSTR(ltrim(v.text),1,LENGTH('PROCEDURE')))"TYPE"
    FROM dba_source v
    WHERE (TRIM(ltrim(v.text)) LIKE ('FUNCTION%') OR TRIM(ltrim(v.text)) LIKE ('PROCEDURE%')) AND
                v.type IN ('PACKAGE','FUNCTION','PROCEDURE')
    ORDER BY V.OWNER,V.name,v.text;Note: the translate, substr, etc function can be simplified based on your needs
    in my case, how developers created the function and procedure is quite messy.
    thanks

  • Function (Fn + F1-12) Keys not working; Yoga 13

    Hey,
    I just got my Yoga 13 a few days ago, I've let the system update itself. But I havent been able to find a solution for the Fn Keys... (Like Fn+F1/F2 for volume control...etc)
    Anyone have any ideas how to fix this or what I may need to.... Reinstall?
    Any help would be great! Thanks!
    Romeo 
    Solved!
    Go to Solution.

    mattcoz wrote:
    You only use the Fn key if you want to use the F1,F2,etc functions. The volume control and other functions are the defaults.
    I don't quite understand what you mean; But when I press Fn+F1; It opens 'Help' instead of 'Mute'.. Just like when I press F1 without the Fn... Does that make sense? :s
    Romeo

  • Fieldpoint config and functions

    hi,
      i connected a fp tc 120 i/o module and fp1000 network module.
    successfully configured but where to save the configuration file?
    i cannot see any fieldpoint read, write, etc functions in the block diagram of labview version 8.2.  from where do i get those functions and where to save them?

    Hi kunal227,
    You will want to save your configuration file somewhere you can easily find so
    if you want to load this specific .iak file again, you can do so.
    You should be able to find the FieldPoint VI's in LabVIEW 8.2 under the
    Measurement I/O palette.  On that palette, you will find the FieldPoint
    palette.  If you do not have this, it could be that you have the wrong
    version of FieldPoint installed on your computer, or you do not have support
    for LabVIEW 8.2 installed.
    To verify that you have the correct version of FieldPoint installed, open
    Measurement and Automation Explorer, expand the Software tab under My System,
    and select FieldPoint.  The window on the right will display the version
    of the driver.  For FieldPoint to work, you need to have FieldPoint
    version 5.0 or later installed.
    If you have verified that you have FieldPoint 5.0 or later installed on your
    machine, but still cannot see the FieldPoint VI's in LabVIEW, you will need to
    verify that you have installed support for LabVIEW 8.2.  To check this, go
    to Add or Remove Programs in the Control Panel, select National Instruments
    Software, click the Change/Remove button, this will bring up a National
    Instruments Software window, select NI FieldPoint, and click the Modify
    button.  Now, you will see what FieldPoint features you have
    installed.  Make sure that the box next to LabVIEW 8.2 has an image of a
    hard drive and not an X.  If the box next to LabVIEW 8.2 has an X, click
    on the box and select Install this Feature.
    Please let me know if you have any further questions by replying to this post.
    Message Edited by cphuong on 05-31-2007 09:49 AM
    Regards,
    Ching P.
    DAQ and Academic Hardware R&D
    National Instruments
    Attachments:
    FieldPoint Version.JPG ‏52 KB
    FP_LV_Support.JPG ‏64 KB

  • KDE4: Konqueror: No copy, paste, etc?

    Edit: .. what in the hell is going on? It seemed to be fixed for some bizarre reason after installing konq-plugins.. Then randomly goes away again. Then comes back again. Removing konq-plugins doesn't reproduce it back to it's original no-cut-or-paste state.
    Hey guys,
    This is probably a simple problem, but for the life of me I can't figure it out. I have just about no hair left on my head from switching over to this (again..).
    Simply, the copy/paste/etc functions are greyed out on -anything- in konqueror. Everything. However, it has a menu "Copy to.." that appears to work fine..
    Btw, they appear to work fine in dolphin, but I very much dislike dolphin.
    Wtf?
    Ideas?
    Last edited by FrozenFox (2008-10-25 17:10:42)

    deltaecho wrote:
    I would suggest filing a bug report - if you haven't done so already - or reinstalling kdebase.  They seem to work fine on my PC.
    Out of curiosity, what's so bad about Dolphin?  It's developed by the same people who develop Konqueror, and has the option of opening multiple, Konqueror-style tabs and splitting the current view (but only into 2 windows - which is all most people need).  Beginning with 4.2, Ark's service menus will also be included, so people will be able to easily (un)archive/copy/cut/move/delete/etc. files.
    * I do not use split view on anything, because for me it's extremely counterproductive to have half as much space to see what I'm doing and where I'm going than just open the two destinations in separate tabs/windows and mess with more scrolling and go around my mental map of the folder layout. The way I am, it actually takes more time, not less, to use.
    * It is no where remotely close to as configurable as konqueror
    * I can't get the layout to be like I've used for years. Kind of close, but no cigar:
        There is no apparent way to put a location bar (which I want to be the usual editable kind as opposed to only editable when you click next to it -- -always-.) into the same bar as the back/fwd etc. I can only have a separate, space-wasting navigation bar. I don't see 'location' anywhere in the toolbar options, or a way to get rid of the navigation bar. I need to do both. I dont see a point in wasting so much space to the right of both the main icons and the location bar when you could combine them.
    * I don't understand the point of yet another file browser when konqueror beats it hands down and is essentially loaded into the system whether or not it's used on my setup.
    * Dolphin is not a web browser, which I used konqueror for occasionally.
    * I don't think most of my service menus work with it. Though this I have not determined for sure, because of the above.
    I could probably think of more, but these are the most obvious reasons. I just don't like it. It feels like a nerfed nautilus to me.
    .... but in other news, Dolphin solved a bug I was having in konqueror somehow that I was about to post. Basically, the icons were huge. When I would resize them and their previews in the config utility, it would work, but then reset itself upon re-launching konqueror.  I used the identical utility in dolphin to change its icon sizes, and magically they are working correctly in konqueror now on every launch. Weird. Maybe loading dolphin to check whether copy/paste works there also fixed copy/paste in konq somehow, as it just did with these icons, and installing konq-plugins was just a coincidence at the same time. Within these few minutes that the icons did not save size settings, I have done nothing but play with dolphin and install konq-plugins. Very bizarre.
    Kde4 is so buggy.. =/ I'd post bug reports on these things, but it doesn't do much good when I can't reproduce the problem or have certainty about what solved the issue in the first place.
    Last edited by FrozenFox (2008-10-25 17:43:12)

Maybe you are looking for