Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is scalblnf in C?

Abdul Monum

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

scalblnf in C is used to multiply a floating-point value by FLT_RADIX raised to a user-specified value. scalblnf is defined in the math.h header file and the function declaration is as follows:

float scalblnf(float arg, long exp);

FLT_RADIX is an integer constant defined in <float.h>. Its value is 2 for most binary systems.

Parameters

arg: floating-point value

exp: long value

Return value

  • No errors: argFLT_RADIXexparg*FLT\_RADIX^{exp}

  • Range error due to underflow: Correct result after rounding

  • Range error due to overflow: ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL

Error handling

Errors are recorded according to the macro constant math_errhandling. Some special cases are handled as follows:

  • If arg is ±0±0, then unmodified arg is returned
  • If arg is ±\infty, then unmodified arg is returned
  • If exp is 00, then unmodified arg is returned
  • If arg is NaN, then NaN is returned

Example

#include <stdio.h>
#include <math.h>
#include <errno.h>
int main()
{
printf("scalblnf(3.0, 2) = %f\n", scalblnf(3.0, 2));
printf("scalblnf(5.0, -3) = %f\n", scalblnf(5.0,-3));
printf("scalblnf(7.0, 0) = %f\n", scalblnf(7.0, 0));
return 0;
}

Explanation

First, we import the math.h header file from the C standard library. The program then prints the output of scalblnf on possible example values.

scalbn, scalbnf, scalbnl, scalbln, and scalblnl perform the same function as scalblnf but differ in the data types of exp and return value.

RELATED TAGS

c

CONTRIBUTOR

Abdul Monum
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring