C scalbln() Function

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

Definition

In C, scalbln() returns x × FLT_RADIXn. On binary systems, FLT_RADIX is 2, so this is like scaling by a power of two with a long exponent.

You pass a double and a long power. Both are required. The result is a double. Include <math.h>. Prefer this over a naive pow loop when you only need radix scaling.

Use scalbn() when the exponent fits in an int. Use scalbln when you need the wider long range for n.

Syntax

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

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

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

Library declarations
C
double scalbln(double x, long n);
float scalblnf(float x, long n);
long double scalblnl(long double x, long n);

Parameters

ParameterDescription
xRequired. The double to scale.
nRequired. The long 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 1.5 by three powers of the radix (usually 2).

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

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

How It Works

  1. Include math.h. That declares scalbln.
  2. Positive n. 1.5 × 8 becomes 12 on binary hosts.
  3. Negative n. On binary hosts: 1.5 / 2 = 0.75.
  4. Use L suffix. 3L marks a long literal.

Example 2 — Print FLT_RADIX

Confirm the radix your platform uses before you reason about the scale factor.

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

int main(void) {
    printf("FLT_RADIX = %d\n", FLT_RADIX);
    printf("scalbln(3, 2) = %.1f\n", scalbln(3.0, 2L));
    return 0;
}

How It Works

  1. Include float.h. That defines FLT_RADIX.
  2. Print radix. Almost always 2.
  3. Scale 3 by 2. On binary hosts: 3 × 4 = 12.
  4. Portable thinking. Write for FLT_RADIX, not only for 2.

Example 3 — Use a Long Exponent

Show a call that needs the long parameter form.

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

int main(void) {
    long n = 10L;
    double x = 1.0;
    double y = scalbln(x, n);

    printf("2^10 scaled from 1 = %.1f\n", y);
    return 0;
}

How It Works

  1. Store n as long. Matches the scalbln signature.
  2. Start at 1. Simple mantissa.
  3. Scale by 10. On binary hosts this is 1024.
  4. Why long? Use this form when exponents may exceed int range.

Frequently Asked Questions

scalbln(x, n) returns x multiplied by FLT_RADIX to the power n, with n as a long.
x is the value to scale. n is the long 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.
Both scale by FLT_RADIX^n. scalbln takes a long exponent; scalbn takes an int exponent.

Next: scalbn()

Scale by FLT_RADIX raised to an int exponent.

scalbn() 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