Commit 8bb1300c
8bb1300c0856Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified
Description
Merge pull request #132 from Halvanhelv/feat/integer-lcm
feat(codegen,runtime): add Integer#lcm
Details
- Commit
- 8bb1300c0856
- Parent
- fd34ce478a74
- Merge parent
- 85665a834671
lib/sp_runtime.hmodifiedView file
@@ -76,6 +76,7 @@
7676
}7777
7878
static mrb_int sp_gcd(mrb_int a,mrb_int b){if(a<0)a=-a;if(b<0)b=-b;while(b){mrb_int t=b;b=a%b;a=t;}return a;}79+
static mrb_int sp_lcm(mrb_int a,mrb_int b){if(a==0||b==0)return 0;mrb_int g=sp_gcd(a,b);if(a<0)a=-a;if(b<0)b=-b;return (a/g)*b;}7980
static mrb_int sp_int_clamp(mrb_int v,mrb_int lo,mrb_int hi){return v<lo?lo:v>hi?hi:v;}8081
static inline char *sp_str_alloc_raw(size_t total_with_null); /* fwd decl */8182
static const char*sp_int_chr(mrb_int n){char*s=sp_str_alloc_raw(2);s[0]=(char)n;s[1]=0;return s;}spinel_codegen.rbmodifiedView file
Loading diff…
test/integer_lcm.rbaddedView file
Loading diff…