Commit c9233382
c9233382b135Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 6 files · +2 added · ~4 modified
Description
Merge pull request #1480 from ryanseys/rs-float-clamp
Add Float#clamp
Details
- Commit
- c9233382b135
- Parent
- f10557d9d8c0
- Merge parent
- dfb43f7f2955
lib/sp_core.cmodifiedView file
@@ -254,6 +254,7 @@
254254
mrb_int sp_powmod(mrb_int base,mrb_int exp,mrb_int mod){if(mod==0)sp_raise_cls("ZeroDivisionError","divided by 0");mrb_int r=1;mrb_int m=mod<0?-mod:mod;if(m==1){r=0;}else{base=base%m;if(base<0)base+=m;while(exp>0){if(exp%2==1)r=r*base%m;exp=exp/2;base=base*base%m;}}if(mod<0&&r>0)r-=m;return r;}255255
mrb_int sp_ceildiv(mrb_int a,mrb_int b){if(b==0)sp_raise_cls("ZeroDivisionError","divided by 0");if(b==-1)return -a;mrb_int q=a/b;if(a%b!=0&&((a^b)>=0))q++;return q;}256256
mrb_int sp_int_clamp(mrb_int v,mrb_int lo,mrb_int hi){return v<lo?lo:v>hi?hi:v;}257+
mrb_float sp_float_clamp(mrb_float v,mrb_float lo,mrb_float hi){return v<lo?lo:v>hi?hi:v;}257258
/* Integer square root via Newton's method -- exact for the full258259
mrb_int range. CRuby raises Math::DomainError on negative input259260
(flattened runtime name "Math_DomainError"). The seed is n/2, notlib/sp_core.hmodifiedView file
Loading diff…
src/analyze_infer.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…
test/float_clamp.rbaddedView file
Loading diff…
test/float_clamp.rb.expectedaddedView file
Loading diff…