Index: django/template/defaultfilters.py
===================================================================
--- django/template/defaultfilters.py	(revision 7320)
+++ django/template/defaultfilters.py	(working copy)
@@ -124,7 +124,10 @@
         d = int(arg)
     except ValueError:
         return force_unicode(f)
-    m = f - int(f)
+    try:
+        m = f - int(f)
+    except OverflowError:
+        return force_unicode(f)
     if not m and d < 0:
         return mark_safe(u'%d' % int(f))
     else:
Index: tests/regressiontests/defaultfilters/tests.py
===================================================================
--- tests/regressiontests/defaultfilters/tests.py	(revision 7320)
+++ tests/regressiontests/defaultfilters/tests.py	(working copy)
@@ -39,6 +39,10 @@
 u''
 >>> floatformat(None)
 u''
+>>> floatformat(float('infinity'))
+u'inf'
+>>> floatformat(float('nan'))
+u'nan'
 
 >>> addslashes(u'"double quotes" and \'single quotes\'')
 u'\\"double quotes\\" and \\\'single quotes\\\''
