Skip to content

Commit 5965dff

Browse files
authored
feat(stdlib): Expose equality operators through Number module (#2296)
1 parent f42264c commit 5965dff

File tree

2 files changed

+356
-0
lines changed

2 files changed

+356
-0
lines changed

stdlib/number.gr

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ provide let (*) = (*)
139139
*/
140140
provide let (/) = (/)
141141

142+
/**
143+
* Computes the remainder of the division of the first operand by the second.
144+
* The result will have the sign of the second operand.
145+
*
146+
* @param num1: The first operand
147+
* @param num2: The second operand
148+
* @returns The modulus of its operands
149+
*
150+
* @example
151+
* use Number.{ (%) }
152+
* assert 10 % 3 == 1
153+
*
154+
* @since v0.7.1
155+
*/
156+
provide let (%) = (%)
157+
142158
/**
143159
* Computes the exponentiation of the given base and power.
144160
*
@@ -155,6 +171,104 @@ provide let (/) = (/)
155171
*/
156172
provide let (**) = (**)
157173

174+
/**
175+
* Checks if the first value is equal to the second value.
176+
*
177+
* @param x: The first value
178+
* @param y: The second value
179+
* @returns `true` if the first value is equal to the second value or `false` otherwise
180+
*
181+
* @example
182+
* use Number.{ (==) }
183+
* assert 1 == 1
184+
*
185+
* @since v0.7.1
186+
*/
187+
provide let (==) = Numbers.numberEq
188+
189+
/**
190+
* Checks if the first value is equal to the second value.
191+
*
192+
* @param x: The first value
193+
* @param y: The second value
194+
* @returns `true` if the first value is equal to the second value or `false` otherwise
195+
*
196+
* @example
197+
* use Number.{ (==) }
198+
* assert 1 == 1
199+
*
200+
* @since v0.7.1
201+
*/
202+
provide let (!=) = (x, y) => !Numbers.numberEq(x, y)
203+
204+
/**
205+
* Checks if the first value is less than the second value.
206+
*
207+
* @param num1: The first value
208+
* @param num2: The second value
209+
* @returns `true` if the first value is less than the second value or `false` otherwise
210+
*
211+
* @example
212+
* use Number.{ (<) }
213+
* assert 1 < 5
214+
*
215+
* @since v0.7.1
216+
*/
217+
provide let (<) = (<)
218+
219+
/**
220+
* Checks if the first value is greater than the second value.
221+
*
222+
* @param num1: The first value
223+
* @param num2: The second value
224+
* @returns `true` if the first value is greater than the second value or `false` otherwise
225+
*
226+
* @example
227+
* use Number.{ (>) }
228+
* assert 5 > 1
229+
*
230+
* @since v0.7.1
231+
*/
232+
provide let (>) = (>)
233+
234+
/**
235+
* Checks if the first value is less than or equal to the second value.
236+
*
237+
* @param num1: The first value
238+
* @param num2: The second value
239+
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
240+
*
241+
* @example
242+
* use Number.{ (<=) }
243+
* assert 1 <= 2
244+
* @example
245+
* use Number.{ (<=) }
246+
* assert 1 <= 1
247+
*
248+
* @since v0.7.1
249+
*/
250+
@unsafe
251+
provide let (<=) = (<=)
252+
253+
/**
254+
* Checks if the first value is greater than or equal to the second value.
255+
*
256+
* @param num1: The first value
257+
* @param num2: The second value
258+
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
259+
*
260+
* @example
261+
* use Number.{ (>=) }
262+
* assert 3 >= 2
263+
* @example
264+
* use Number.{ (>=) }
265+
* assert 1 >= 1
266+
*
267+
* @since v0.7.1
268+
*/
269+
@unsafe
270+
provide let (>=) = (>=)
271+
158272
/**
159273
* Computes the exponentiation of Euler's number to the given power.
160274
*

stdlib/number.md

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,40 @@ use Number.{ (/) }
281281
assert 10 / 2.5 == 4
282282
```
283283

284+
### Number.**(%)**
285+
286+
<details disabled>
287+
<summary tabindex="-1">Added in <code>next</code></summary>
288+
No other changes yet.
289+
</details>
290+
291+
```grain
292+
(%): (num1: Number, num2: Number) => Number
293+
```
294+
295+
Computes the remainder of the division of the first operand by the second.
296+
The result will have the sign of the second operand.
297+
298+
Parameters:
299+
300+
|param|type|description|
301+
|-----|----|-----------|
302+
|`num1`|`Number`|The first operand|
303+
|`num2`|`Number`|The second operand|
304+
305+
Returns:
306+
307+
|type|description|
308+
|----|-----------|
309+
|`Number`|The modulus of its operands|
310+
311+
Examples:
312+
313+
```grain
314+
use Number.{ (%) }
315+
assert 10 % 3 == 1
316+
```
317+
284318
### Number.**(\*\*)**
285319

286320
<details>
@@ -321,6 +355,214 @@ use Number.{ (**) }
321355
assert 10 ** 2 == 100
322356
```
323357

358+
### Number.**(==)**
359+
360+
<details disabled>
361+
<summary tabindex="-1">Added in <code>next</code></summary>
362+
No other changes yet.
363+
</details>
364+
365+
```grain
366+
(==): (x: Number, y: Number) => Bool
367+
```
368+
369+
Checks if the first value is equal to the second value.
370+
371+
Parameters:
372+
373+
|param|type|description|
374+
|-----|----|-----------|
375+
|`x`|`Number`|The first value|
376+
|`y`|`Number`|The second value|
377+
378+
Returns:
379+
380+
|type|description|
381+
|----|-----------|
382+
|`Bool`|`true` if the first value is equal to the second value or `false` otherwise|
383+
384+
Examples:
385+
386+
```grain
387+
use Number.{ (==) }
388+
assert 1 == 1
389+
```
390+
391+
### Number.**(!=)**
392+
393+
<details disabled>
394+
<summary tabindex="-1">Added in <code>next</code></summary>
395+
No other changes yet.
396+
</details>
397+
398+
```grain
399+
(!=): (x: Number, y: Number) => Bool
400+
```
401+
402+
Checks if the first value is equal to the second value.
403+
404+
Parameters:
405+
406+
|param|type|description|
407+
|-----|----|-----------|
408+
|`x`|`Number`|The first value|
409+
|`y`|`Number`|The second value|
410+
411+
Returns:
412+
413+
|type|description|
414+
|----|-----------|
415+
|`Bool`|`true` if the first value is equal to the second value or `false` otherwise|
416+
417+
Examples:
418+
419+
```grain
420+
use Number.{ (==) }
421+
assert 1 == 1
422+
```
423+
424+
### Number.**(<)**
425+
426+
<details disabled>
427+
<summary tabindex="-1">Added in <code>next</code></summary>
428+
No other changes yet.
429+
</details>
430+
431+
```grain
432+
(<): (num1: Number, num2: Number) => Bool
433+
```
434+
435+
Checks if the first value is less than the second value.
436+
437+
Parameters:
438+
439+
|param|type|description|
440+
|-----|----|-----------|
441+
|`num1`|`Number`|The first value|
442+
|`num2`|`Number`|The second value|
443+
444+
Returns:
445+
446+
|type|description|
447+
|----|-----------|
448+
|`Bool`|`true` if the first value is less than the second value or `false` otherwise|
449+
450+
Examples:
451+
452+
```grain
453+
use Number.{ (<) }
454+
assert 1 < 5
455+
```
456+
457+
### Number.**(>)**
458+
459+
<details disabled>
460+
<summary tabindex="-1">Added in <code>next</code></summary>
461+
No other changes yet.
462+
</details>
463+
464+
```grain
465+
(>): (num1: Number, num2: Number) => Bool
466+
```
467+
468+
Checks if the first value is greater than the second value.
469+
470+
Parameters:
471+
472+
|param|type|description|
473+
|-----|----|-----------|
474+
|`num1`|`Number`|The first value|
475+
|`num2`|`Number`|The second value|
476+
477+
Returns:
478+
479+
|type|description|
480+
|----|-----------|
481+
|`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
482+
483+
Examples:
484+
485+
```grain
486+
use Number.{ (>) }
487+
assert 5 > 1
488+
```
489+
490+
### Number.**(<=)**
491+
492+
<details disabled>
493+
<summary tabindex="-1">Added in <code>next</code></summary>
494+
No other changes yet.
495+
</details>
496+
497+
```grain
498+
(<=): (num1: Number, num2: Number) => Bool
499+
```
500+
501+
Checks if the first value is less than or equal to the second value.
502+
503+
Parameters:
504+
505+
|param|type|description|
506+
|-----|----|-----------|
507+
|`num1`|`Number`|The first value|
508+
|`num2`|`Number`|The second value|
509+
510+
Returns:
511+
512+
|type|description|
513+
|----|-----------|
514+
|`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
515+
516+
Examples:
517+
518+
```grain
519+
use Number.{ (<=) }
520+
assert 1 <= 2
521+
```
522+
523+
```grain
524+
use Number.{ (<=) }
525+
assert 1 <= 1
526+
```
527+
528+
### Number.**(>=)**
529+
530+
<details disabled>
531+
<summary tabindex="-1">Added in <code>next</code></summary>
532+
No other changes yet.
533+
</details>
534+
535+
```grain
536+
(>=): (num1: Number, num2: Number) => Bool
537+
```
538+
539+
Checks if the first value is greater than or equal to the second value.
540+
541+
Parameters:
542+
543+
|param|type|description|
544+
|-----|----|-----------|
545+
|`num1`|`Number`|The first value|
546+
|`num2`|`Number`|The second value|
547+
548+
Returns:
549+
550+
|type|description|
551+
|----|-----------|
552+
|`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
553+
554+
Examples:
555+
556+
```grain
557+
use Number.{ (>=) }
558+
assert 3 >= 2
559+
```
560+
561+
```grain
562+
use Number.{ (>=) }
563+
assert 1 >= 1
564+
```
565+
324566
### Number.**exp**
325567

326568
<details disabled>

0 commit comments

Comments
 (0)