diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 6a8905c1ee24f282d3fed4002edd6ccc639151b7..64197060beeaf5f75afce62ebd3f7d41265e7d57 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,13 @@
+2005-06-15  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+	PR libfortran/21950
+	* intrinsics/c99_functions.c (scalbn): Provide fallback
+	implementation for scalbn.
+	* c99_protos.h: Prototype for scalbn.
+	* configure.ac: Add check for scalbn.
+	* configure: Regenerate.
+	* config.h.in: Regenerate.
+
 2005-06-14  Thomas Koenig  <Thomas.Koenig@online.de>
 
 	* intrinsics/eoshift0.c:  Removed prototype for eoshift0.
@@ -47,10 +57,10 @@
 	For complex, call internal_pack_c4 if size==8 and
 	internal_pack_c8 if size==16.
 	* runtime/in_unpack_generic.c: For real, integer and logical
-        call internal_unpack_4 if size==4 and internal_unpack_8 if
-        size==8.
-        For complex, call internal_unpack_c4 if size==8 and
-        internal_unpack_c8 if size==16.
+	call internal_unpack_4 if size==4 and internal_unpack_8 if
+	size==8.
+	For complex, call internal_unpack_c4 if size==8 and
+	internal_unpack_c8 if size==16.
 	* generated/in_pack_i4.c:  Regenerated.
 	* generated/in_pack_i8.c:  Regenerated.
 	* generated/in_unpack_i4.c:  Regenerated.
diff --git a/libgfortran/c99_protos.h b/libgfortran/c99_protos.h
index 521f205399a659a52fdbde6d1e782013e6c214e4..4deb25ceed13f2bc0fd9ed2445a27a58cee5595c 100644
--- a/libgfortran/c99_protos.h
+++ b/libgfortran/c99_protos.h
@@ -89,6 +89,10 @@ extern float logf(float);
 extern float log10f(float);
 #endif
 
+#ifndef HAVE_SCALBN
+extern double scalbn(double, int);
+#endif
+
 #ifndef HAVE_SCALBNF
 extern float scalbnf(float, int);
 #endif
diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in
index f1a5628a02086ca5e6e9b9af06366a6fab44f943..aaf663ecd332f49888c4b0c978f78ac3903d503d 100644
--- a/libgfortran/config.h.in
+++ b/libgfortran/config.h.in
@@ -168,6 +168,9 @@
 /* libm includes roundf */
 #undef HAVE_ROUNDF
 
+/* libm includes scalbn */
+#undef HAVE_SCALBN
+
 /* libm includes scalbnf */
 #undef HAVE_SCALBNF
 
diff --git a/libgfortran/configure b/libgfortran/configure
index 1bb87b8c0364d696a67a607e7e7abaa6c326cf5d..aaaf9f67ea541d8d216ad617093d91ce45cf2e66 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -9401,6 +9401,83 @@ _ACEOF
 
 fi
 
+echo "$as_me:$LINENO: checking for scalbn in -lm" >&5
+echo $ECHO_N "checking for scalbn in -lm... $ECHO_C" >&6
+if test "${ac_cv_lib_m_scalbn+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm  $LIBS"
+if test x$gcc_no_link = xyes; then
+  { { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5
+echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char scalbn ();
+int
+main ()
+{
+scalbn ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_m_scalbn=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_m_scalbn=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_m_scalbn" >&5
+echo "${ECHO_T}$ac_cv_lib_m_scalbn" >&6
+if test $ac_cv_lib_m_scalbn = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SCALBN 1
+_ACEOF
+
+fi
+
 echo "$as_me:$LINENO: checking for sinf in -lm" >&5
 echo $ECHO_N "checking for sinf in -lm... $ECHO_C" >&6
 if test "${ac_cv_lib_m_sinf+set}" = set; then
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index efda28009d282e8a878bfea6945ed713f84ad908..c4c70fbc85ccd344688a9b36492e501c7d7cad35 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -201,6 +201,7 @@ AC_CHECK_LIB([m],[powf],[AC_DEFINE([HAVE_POWF],[1],[libm includes powf])])
 AC_CHECK_LIB([m],[round],[AC_DEFINE([HAVE_ROUND],[1],[libm includes round])])
 AC_CHECK_LIB([m],[roundf],[AC_DEFINE([HAVE_ROUNDF],[1],[libm includes roundf])])
 AC_CHECK_LIB([m],[scalbnf],[AC_DEFINE([HAVE_SCALBNF],[1],[libm includes scalbnf])])
+AC_CHECK_LIB([m],[scalbn],[AC_DEFINE([HAVE_SCALBN],[1],[libm includes scalbn])])
 AC_CHECK_LIB([m],[sinf],[AC_DEFINE([HAVE_SINF],[1],[libm includes sinf])])
 AC_CHECK_LIB([m],[sinhf],[AC_DEFINE([HAVE_SINHF],[1],[libm includes sinhf])])
 AC_CHECK_LIB([m],[sqrtf],[AC_DEFINE([HAVE_SQRTF],[1],[libm includes sqrtf])])
diff --git a/libgfortran/intrinsics/c99_functions.c b/libgfortran/intrinsics/c99_functions.c
index 6296904b56da55687e613e233f683f35a7ab3f7a..dfdb71e74272a34899b4812a05232337894ba9dc 100644
--- a/libgfortran/intrinsics/c99_functions.c
+++ b/libgfortran/intrinsics/c99_functions.c
@@ -154,6 +154,14 @@ log10f(float x)
 }
 #endif
 
+#ifndef HAVE_SCALBN
+double
+scalbn(double x, int y)
+{
+  return x * pow(FLT_RADIX, y);
+}
+#endif
+
 #ifndef HAVE_SCALBNF
 float
 scalbnf(float x, int y)