Skip to content

Commit fc5dc62

Browse files
committed
add fps_is_invertible
1 parent c342857 commit fc5dc62

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

examples/example12.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int main()
1616
modulus m = 7;
1717

1818
fps_print(s, n, "S");
19+
printf("S invertible? -> %d\n", fps_is_invertible(s));
1920
fps_newton_inverse(s, n, u, m);
2021

2122
return 0;

lib/fps.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ void fps_print(const fps s, prec n, char *name)
6464
}
6565
}
6666

67+
/**
68+
* Returns 1 if the formal power series s is invertible (if s0 != 0), 0 else.
69+
*
70+
* @param s fps
71+
* @return 1 if the fps is invertible, 0 else
72+
*/
73+
int fps_is_invertible(const fps s)
74+
{
75+
return s[0] == 0 ? 0 : 1;
76+
}
77+
6778
/**
6879
* Inverts a formal power series using the Newton's method.
6980
*

lib/fps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ typedef polynomial fps;
1717
typedef unsigned int prec;
1818

1919
void fps_print(const fps s, prec n, char *name);
20+
int fps_is_invertible(const fps s);
2021
void fps_newton_inverse(const fps s, prec n, fps u, modulus m);

0 commit comments

Comments
 (0)