I want a overflow-safe function that round a double like std::round in addition it can handle the number of significant decimal digts.  f.e.  round(-17.747, 2) -&gt; -17.75 round(-9.97729, 2) -&gt; -9.98 round(-5.62448, 2) -&gt; -5.62 round(std::numeric_limits&lt;double&gt;::max(), 10) ...   My first attempt was  double round(double value, int precision) {     double factor=pow(10.0, precision);     return floor(value*factor+0.5)/factor; }   but this can easily overflow.  Assuming IEEE, it is possible to decrease the possibility of overflows, like this.  double round(double value, int precision) {     // assuming IEEE 754 with 64 bit representation     // the number of significant digits varies between 15 and 17      precision=std::min(17, precision);     double factor=pow(10.0, precision);     return floor(value*factor+0.5)/factor; }   But this still can overflow.  Even this performance disaster does not work.  double round(double value, int precision) {     std::stringstream ss;     ss &lt;&lt; std::setprecision(precision) &lt;&lt; value;     std::string::size_type sz;     return std::stod(ss.str(), &amp;sz); } round(std::numeric_limits&lt;double&gt;::max(), 2.0) // throws std::out_of_range   Note:    I'm aware of setprecision, but i need rounding not only for displaying purpose. So that is not a solution. Unlike this post here  , my question is especially on overflow safety and in C++ (the anwser in the topic above are Java-specific or do not handle overflows)
What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.  I also would like only significant digits to be displayed - i.e. there should not be any trailing zeroes.  I know one method of doing this is to use the String.format method:  String.format("%.5g%n", 0.912385);   returns:  0.91239   which is great, however it always displays numbers with 5 decimal places even if they are not significant:   String.format("%.5g%n", 0.912300);   returns:  0.91230   Another method is to use the DecimalFormatter:  DecimalFormat df = new DecimalFormat("#.#####"); df.format(0.912385);   returns:  0.91238   However as you can see this uses half-even rounding. That is it will round down if the previous digit is even. What I'd like is this:  0.912385 -&gt; 0.91239 0.912300 -&gt; 0.9123   What is the best way to achieve this in Java?
Are the limits $\lim\limits_{n\to \infty }\left|\frac{a_{n+1}}{a_n}\right|\,$ and $\lim\limits_{n\to \infty }\sqrt[n]{|a_n|}\,$ equal? Let consider the power series $$ \sum_{k=1}^\infty a_kx^k. $$ We know that it converges when  $$\lim_{n\to \infty }\sqrt[n]{|a_n|}|x|&lt; 1\quad\text{or}\quad |x|&lt; \frac{1}{\lim_{n\to \infty }\sqrt[n]{|a_n|}}$$  But D'Alembert test tells us that it converges if $$|x|&lt; \frac{1}{\lim_{n\to \infty }\left|\frac{a_{n+1}}{a_n}\right|},$$ so since the radius of convergence is unique, we should have that $$\lim_{n\to \infty }\sqrt[n]{|a_n|}=\lim_{n\to \infty }\left|\frac{a_{n+1}}{a_n}\right|.$$  I tried to prove it, but this result looks strange to me. So if it doesn't work always, how can we have those to limit as radius of convergence? I guess the equality of those two limit should be true most of the time.  So under what conditions is it true? Negative probabilities in quantum physics Can we get wordpress.stackexchange.com added to the list of off-topic redirection sites? I'm noticing a lot of WordPress questions being asked on Stack Overflow lately. I can't flag these to be moved to wordpress.stackexchange.com because it's not in the list:    Can it be added? Are there any other Stack Exchange sites worth adding? This question is similar, but not identical to:   Whereas the aforementioned question is about whether the hand’s movement is measured from the hand’s point of view or from the caster’s, this question revolves around the total distance the hand can travel to reach its destination.  To illustrate, let me give an example: Two narrow stone pillars stand next to each other, 10 feet apart. They are several kilometers high and on top of each pillar stands a wizard. One wizard casts Maximillian's Earthen Grasp and lets the hand made from compacted soil rise from the ground on his own pillar. With another action, he wants to move the hand in order to restrain the other wizard, who is within range of 30 feet.  Would the hand retract into his own pillar, then rise again from the ground on the other pillar? Or would the hand move several kilometers down the first pillar, across the floor, then several kilometers up the second pillar? What if both pillars would float in the Astral Plane, without a direct ground-based connection between them?  This might seem like a stupid and unnecessary convoluted question, but lo and behold, something similar happened in one of my games. Most of the time when I mixed different nuts in a bowl, I observed that the big Brazil nuts were always on top while the small peanuts settled near the base. No matter how you take it, if the big nuts are put at the bottom and then the small nuts are poured, then also after some time the big ones will come to the top. Will not the gravity attract those big nuts more and eventually will they not remain at the base? But it doesn't happen!   I googled it and found the term Brazil-nut Effect but couldn't find any proper explanation. What is the physical explanation for this effect? How to code to skip a shapefile, if it doesn't exist? So if shapefile 'AAA010' does not exist, how can I skip the Merge and Clip and move on to the next part of the script? If possible I would like to keep the current script as it is, but by just adding else or if, Sorry still trying to learn the ins and outs.  import os, fnmatch, arcpy   arcpy.env.workspace = r'C:\Users\sysadmin\Desktop\DataMagement\Comp_3\SA_MGCP3.gdb'   fcMerged = 'MergedFeatureClass' fcClipped = 'fcClipped' fcToClip = r'C:\Users\sysadmin\Desktop\DataMagement\Country.shp'  filesMatched = list()  for root, subfolders, files in os.walk (r'C:\Users\sysadmin\Desktop\DataMagement\MGCP_Raw'):      for f in fnmatch.filer(files, 'AAA010.shp'):              filesMatched.append(os.path.join(root,f))      if filesMatched:         print ' files found - merging'         arcpy.Merge_management (filesMatched, fcMerged)         arcpy.Clip_analysis (fcMerged, fcToClip,fcClipped)      else:          print 'nothing found - skipping' Idiom for explaining something to someone who clearly knows the topic (probably better than you) Python Ctypes - loading dll throws OSError: [WinError 193] %1 is not a valid Win32 application Ierator and for-each loop both we use for traverse no of items, I have used for-each many times but I am not clear about iterator, means when we should use ierator. I am studying salesforce workbook example..  global class CustomIterable implements iterator&lt;Account&gt;{    public List&lt;Account&gt; accs {get; set;}   public Integer i {get; set;}    public CustomIterable(){      accs =[SELECT Name fROM Account limit 5];      i = 0;              }   global boolean hasNext(){          if(i &gt;= accs.size()) {          return false;         } else {          return true;         }    }    global Account next(){          if(i == 8){return null;}          i++;          return accs[i-1];     } }   //------------  @isTest(seealldata=true) global class IteratorClass{     public static testmethod void main(){          IteratorClass obj = new IteratorClass();         Iterator&lt;Account&gt; acs =  obj.Iterator();         system.debug(acs);      }     global Iterator&lt;Account&gt; Iterator(){             return new CustomIterable();          }  } How to remove all white spaces just between brackets [] using Unix tools? What is scientific mind? How do I delete all Folders with a specific name (e.g. 128Kbps_Songs) without deleting its files  For example if I have directory "MP3_SONGS" with subdirectories "A", "B", "C" and each subdirectory has MANY directory Contains Film Name "FILM_NAME1", "FILM_NAME2", "FILM_NAME3" in it, In That Each Film NAme I have specific Folder NAme (128Kbps_Songs) in this "128Kbps_Songs" Folder I have That Film mp3 Songs Files  how can I remove the Folder "128Kbps_Songs", in Each Film_Name directory and Have to get these mp3 songs in that FILM_NAME..   ( Have to Delete 128Kbps_Songs Folder in all FILM_NAME without deleting the mp3 Songs in it, have to get the mp3 in FILM_NAME Directory..  MP3_SONGS (Parent Directory) ------ A , B, C  A (Sub Directory1) ------ FILM_NAME1 , FILM_NAME2 B (Sub Directory2) ------ FILM_NAME3 , FILM_NAME4 c (Sub Directory3) ------ FILM_NAME5 , FILM_NAME6  FILM_NAME1 (Directory) ---- 128Kbps_Songs (Directory) ------ FILM_NAME1 (MP3 Files) FILM_NAME2 (Directory) ---- 128Kbps_Songs (Directory) ------ FILM_NAME2 (MP3 Files)  FILM_NAME3 (Directory) ---- 128Kbps_Songs (Directory) ------ FILM_NAME3 (MP3 Files) FILM_NAME4 (Directory) ---- 128Kbps_Songs (Directory) ------ FILM_NAME4 (MP3 Files)  FILM_NAME5 (Directory) ---- 128Kbps_Songs (Directory) ------ FILM_NAME5 (MP3 Files) FILM_NAME6 (Directory) ---- 128Kbps_Songs (Directory) ------ FILM_NAME6 (MP3 Files)  Need Files in: FILM_NAME1 (Directory)  ------ FILM_NAME1 (MP3 Files) FILM_NAME2 (Directory)  ------ FILM_NAME2 (MP3 Files)  FILM_NAME3 (Directory)  ------ FILM_NAME3 (MP3 Files) FILM_NAME4 (Directory)  ------ FILM_NAME4 (MP3 Files)  FILM_NAME5 (Directory)  ------ FILM_NAME5 (MP3 Files) FILM_NAME6 (Directory)  ------ FILM_NAME6 (MP3 Files) I am attempting to settle a friendly bet.  Would a pendulum swing indefinitely in a hypothetical vacuum (i.e. no air resistance) having a hypothetical frictionless bearing (i.e. no energy lost due to friction) assuming the following   The frictionless vacuum is on Earth (9.8 m/s^2). The pendulum is already in motion and no other external forces other than gravity act on the pendulum. I want to determine $$\lim\limits_{(x,y) \to (0,0)} \frac{x^2·y^3}{x^4+y^6}$$  I'm sure the limit exists, it's zero because I tried to find other different limits in line and parabola points ($(x,mx)$ and $(x,mx^2)$) but every time I got zero. So, I have to use the definition or sequences to confirm. Multivariable limit proof: $\lim\limits_{(x,y)\rightarrow (0,0)}\frac{\left|x\right|^a\left|y\right|^b}{\left|x\right|^c + \left|y\right|^d} = 0$ I have a stupid self-answered question. Should I accept my own answer? was genuine at the time, but I realised that  gave the right advice, but required me to restart my Linux (which wasn't mentioned in the solution).  It's a bit of a  question and  points to me not deleting it.  But it seems hugely self-aggrandizing to accept my own answer. Should I? Trying to rig a Map I'm trying to make a "simple" accordion map in Blender 2.79, for animated and still render purposes.  I will map graphics onto each face, and I don't want the faces to get stretched/distorted.  I do however, want to be able to create a hinge-type rig, to be able to fold open and close the map like an accordion without having to manually position each face edge (which would distort the faces anyways).  I looked into using an Armature, but the faces got distorted. I tried to use a Hinge constraint, but I if understand correctly, it would require each flap of the map to be a distinct element - I don't want that. I found solutions involving Weight painting, but I don't think I want any of the map's flaps to be anchored - also there is only one face per element and I don't know if Weight Painting is appropriate.    How can I rig this map properly to open it and close it without any distortion? Should I use "who" or "which" when referring to a specific animal species? I'd like to know what option to use, specifically when referring to a species by its scientific name. Splitting ethernet cable I have one ethernet cable that runs into my TV cabinet. It comes from a router in my closet. The router splits the main feed into the home into six runs that run through out the house. I now have several components in my TV cabinet that work best if they are connected to a hard line and not WiFi. Can I split the one cable in my TV cabinet into three or four lines to run to these other components, i.e.: playstation, Receiver,TV antenna box etc. If so, what items do I need to purchase? Thanks for your help. difference between over and for I have a simple question.     over centuries / for centuries   what is the difference?  Thank you.