Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is nextafterf in C/C++?

Behzad Ahmad

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.

Answers Code

We use the nextafterf function to get the next representable floating-point value after the value of the first parameter. It is a variation of nextafter()used when the arguments are of type float.

Library for C

#include<math.h>

Library for C++

#include<cmath>

Syntax

float nextafterf( float a, float b);

Parameters

a: We start from this float value.

b: We go towards this float value.

Return values

The function returns the next representable floating-point value starting from a, moving towards b.

If a and b are equal, then the function returns b.

Code

#include <math.h>
#include <stdio.h>
int main()
{
float answer;
answer = nextafterf( 1.5, 2.0 );
printf("The next representable float is : %.20g\n", answer); //%0.20g is used to represent 20 digits in the floating point number
return 0;
}
C example of function

RELATED TAGS

c

CONTRIBUTOR

Behzad Ahmad
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.

Answers Code
Keep Exploring