Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is nexttowardl() in C?

Kainat Asif

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.

The nexttowardl() function produces the smallest possible value after a number in a given direction. The declaration of nexttowardl() is shown below:

long double nexttowardl (long double num, long double dir);

Parameters

  • num: The base number
  • dir: The direction of the floating point with respect to num

Return value

The nexttowardl() function returns the next representable long double after num in the direction of dir.

Library

To use the nexttowardl() function, include the following library:

#include <math.h>

Example

Consider the code snippet below, which demonstrates the implementation of nexttowardl():

#include <stdio.h>
#include <math.h>
int main() {
long double a = 0.0;
long double b = 2.0;
long double c = -2.0;
long double x = nexttowardl(a, b);
long double y = nexttowardl(a, c);
printf("nexttowardl ( %Lf, %Lf ) = ( %Le) \n", a, b, x);
printf("nexttowardl ( %Lf, %Lf ) = ( %Le) \n", a, c, y);
return 0;
}

Explanation

The nexttowardl() function is used in lines 10 and 11 to compute the next representable floating-point number after a in the direction of b and c.

RELATED TAGS

c

CONTRIBUTOR

Kainat Asif
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