Skip to content

Commit d212d48

Browse files
Update example.c
Signed-off-by: Harsh Mathur <[email protected]>
1 parent 6d7843d commit d212d48

File tree

1 file changed

+8
-13
lines changed
  • lib/node_modules/@stdlib/math/base/special/lcmf/examples/c

1 file changed

+8
-13
lines changed

lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/example.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,19 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/lcmf.h"
20+
#include <stdint.h>
2021
#include <stdio.h>
2122

2223
int main( void ) {
23-
// Define two float arrays to work with floating-point numbers
24-
const float nums_a[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 10.0f, 15.0f, 20.0f };
25-
const float nums_b[] = { 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 15.0f, 20.0f, 25.0f };
26-
27-
// Variable to store LCM result
28-
float result;
24+
float y;
2925
int i;
3026

31-
// Loop over the arrays and compute LCM of pairs
32-
for ( i = 0; i < 9; i++ ) {
33-
// Compute the LCM of two floating-point numbers
34-
result = stdlib_base_lcmf( nums_a[i], nums_b[i] );
35-
36-
// Print the result
37-
printf( "LCM( %.2f, %.2f ) = %.2f\n", nums_a[i], nums_b[i], result );
27+
const float frac[] = { 0.5f, 5.0f, 0.0f, 3.5f, 7.9f };
28+
const int32_t exp[] = { 3, -2, 20, 39, 14 };
29+
30+
for ( i = 0; i < 5; i++ ) {
31+
y = stdlib_base_lcmf( frac[ i ], exp[ i ] );
32+
printf( "ldexpf(%.2f, %d) = %f\n", frac[ i ], exp[ i ], y );
3833
}
3934

4035
return 0;

0 commit comments

Comments
 (0)