How can I prevent/detect an underflow in a Postgresql calculation that uses EXP()

I am receiving a value out of range: underflow error from pgsql, in a query that uses the EXP(x) function. What values of x trigger this? How do I prevent or detect it?


The function exp is called the exponential function, and its inverse is the natural logarithm, or logarithm to base e. The number e is also commonly defined as the base of the natural logarithm

In other words, exp(x) and e^x are the same function. However, since e is a transcendental number, and therefore irrational, its value cannot be given exactly.

The Numerical value of e truncated to 10 decimal places is 2.71828 1828

So, the function exp(x) is technically valid for all values of x, but practically speaking, you can limit them. For example, if you limit them to +/- 700 you should cover all cases covering the range

exp(700) = 1.01423205 × 10^304 exp(-700) = 9.85967654 × 10^-305

More than that depends on your application


A workaround I'm using is to figure check range on my arguments using 'CASE' than fall back to a default if it's out of reasonable scope:



  • underflow and log values in java
  • How To Append an Integer (with an Integer) in C++
  • PHP - Get length of digits in a number
  • Is Time complexity O(N) or O(Log N)?
  • Is complexity O(log(n)) equivalent to O(sqrt(n))?
  • GLM fails to compile with g++/C++11
  • Numpy sum keepdims error
  • Calculating sigmoid value of a bigdecimal in java
  • jboss-fuse-6.3.0.redhat-187 Fabric ssh script Error - Command not found: function
  • Good interpolation method for color mixing?
  • How can I prevent/detect an underflow in a Postgresql calculation that uses EXP()
  • Best practice for assets in codeigniter [closed]
  • where to place common jars in tomcat v6.0 server, which will accessible by all the apps deployed?
  • How much external data is too much? (XML or JSON)
  • Java DecimalFormat creates error when enforcing exponent sign
  • Prolog: Multiplying 2 lists with 1 of them not instantiated?
  • Sum, Avg, Max, Min, Count of NULL values
  • Word Base/Stem Dictionary
  • How to fix the Google Map API when print the whole page?
  • How do you use an fbx file in OpenGL on iOS?
  • How to update the UI immediately when a new record is added? Related to ember-cli-pagination
  • Can I somehow use the to_field parameter in a Django ManyToMany field?
  • Convert ctime to unicode and unicode to ctime python
  • What is an Artifact?
  • Ignore “The” when sorting a View in Drupal
  • Regex: Match everything except backreference
  • Oracle ListaGG, Top 3 most frequent values, given in one column, grouped by ID
  • Should I use composite primary keys in Grails?
  • Get localized short date pattern as String?
  • In matplotlib, how do you change the fontsize of a single figure?
  • Spring: No transaction manager has been configured
  • accepts_nested_attributes_for practical form use for in Rails 3
  • Object and struct member access and address offset calculation
  • Generate random number from custom distribution
  • C++ Partial template specialization - design simplification
  • R - Combining Columns to String Based on Logical Match
  • Is there a javascript serializer for JSON.Net?
  • Where to put my custom functions in Wordpress?
  • Buffer size for converting unsigned long to string
  • Binding checkboxes to object values in AngularJs