C scalbn() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, scalbn() returns x × FLT_RADIXn. On binary platforms this is the same family of idea as multiplying by 2n, with n as an int.

You pass a double and an int power. Both are required. The result is a double. Include <math.h>. It is a clean way to change the exponent without calling a general power function.

Related helpers: ldexp(x, exp) multiplies by 2exp specifically, while scalbn uses FLT_RADIX. On binary hosts they often match.

Syntax

Pass the value, then the int exponent. Start with this call.

C
scalbn(1.5, 3);
CallWhat it does
scalbn(1.5, 3);Returns 12 on binary platforms (1.5 × 2³).

Include <math.h>. On GCC, link with -lm. n is an int.

Library declarations
C
double scalbn(double x, int n);
float scalbnf(float x, int n);
long double scalbnl(long double x, int n);

Parameters

ParameterDescription
xRequired. The double to scale.
nRequired. The int power of FLT_RADIX. It can be negative.

Return Value

Return ValueDescription
Scaled doublex multiplied by FLT_RADIX raised to n.

C Examples

Example 1 — Basic Radix Scale

Scale a simple value up and down.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("%.1f\n", scalbn(1.5, 3));
    printf("%.2f\n", scalbn(1.5, -1));
    return 0;
}

How It Works

  1. Include math.h. That declares scalbn.
  2. n = 3. On binary hosts: 1.5 × 8 = 12.
  3. n = -1. On binary hosts: 1.5 / 2 = 0.75.
  4. Fast scaling. Useful when adjusting exponents.

Example 2 — Compare with ldexp

On a binary machine the results usually match power-of-two scaling.

C
#include <stdio.h>
#include <math.h>
#include <float.h>

int main(void) {
    double a = scalbn(2.25, 4);
    double b = ldexp(2.25, 4);

    printf("FLT_RADIX = %d\n", FLT_RADIX);
    printf("scalbn = %.2f\n", a);
    printf("ldexp  = %.2f\n", b);
    return 0;
}

How It Works

  1. Same inputs. Use 2.25 and 4.
  2. Call both. scalbn and ldexp.
  3. Check radix. Print FLT_RADIX from float.h.
  4. Compare. Equal results are common on binary hosts.

Example 3 — Rebuild a Number with frexp

Split with frexp, then put the pieces back with scalbn when radix is 2.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    int exp = 0;
    double frac = frexp(12.0, &exp);
    double back = scalbn(frac, exp);

    printf("frac = %.3f\n", frac);
    printf("exp  = %d\n", exp);
    printf("back = %.1f\n", back);
    return 0;
}

How It Works

  1. Split 12. frexp gives fraction and power-of-two exponent.
  2. Read frac. A value in [0.5, 1) for normal positives.
  3. Scale back. scalbn(frac, exp) rebuilds the number on binary hosts.
  4. Round trip. Useful when you adjust exponents by hand.

Frequently Asked Questions

scalbn(x, n) returns x multiplied by FLT_RADIX to the power n, with n as an int.
x is the value to scale. n is the int exponent for FLT_RADIX. Both are required.
A double equal to x * FLT_RADIX^n (within floating-point limits).
Include <math.h>. On GCC, link with -lm.
ldexp always scales by a power of two. scalbn scales by FLT_RADIX^n. On binary systems they usually match.

Next: signbit()

Test whether a floating value has its sign bit set.

signbit() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful