Skip to content

Commit 66dce03

Browse files
Jaysukh-409kgryte
andauthored
feat!: add boolean dtype support to array/min-dtype
This commit changes the return value when provided a boolean primitive. Previously, the function returned "generic", and now the function returns "bool". BREAKING CHANGE: return "bool" when provided a boolean To migrate, users explicitly handle "bool" return values. If "generic" is still desired, users should consolidate accordingly. PR-URL: #2556 Ref: #2304 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent f35fdd1 commit 66dce03

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

lib/node_modules/@stdlib/array/min-dtype/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dt = minDataType( '3' );
6868

6969
## Notes
7070

71-
- The function does **not** provide precision guarantees for non-integer-valued real numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) [data type][@stdlib/array/dtypes] for storing numbers having decimals.
71+
- The function does **not** provide precision guarantees for non-integer-valued numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) [data type][@stdlib/array/dtypes] for storing numbers having decimals.
7272

7373
</section>
7474

lib/node_modules/@stdlib/array/min-dtype/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
storing a provided scalar value.
55

66
The function does *not* provide precision guarantees for non-integer-valued
7-
real numbers. In other words, the function returns the smallest possible
7+
numbers. In other words, the function returns the smallest possible
88
floating-point (i.e., inexact) data type for storing numbers having
99
decimals.
1010

lib/node_modules/@stdlib/array/min-dtype/docs/types/index.d.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2021 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -20,15 +20,15 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { RealDataType, ComplexFloatingPointDataType } from '@stdlib/types/array';
23+
import { RealDataType, ComplexFloatingPointDataType, BooleanDataType } from '@stdlib/types/array';
2424
import { ComplexLike } from '@stdlib/types/complex';
2525

2626
/**
2727
* Returns the minimum array data type of the closest "kind" necessary for storing a provided scalar value.
2828
*
2929
* ## Notes
3030
*
31-
* - The function does *not* provide precision guarantees for non-integer-valued real numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) data type for storing numbers having decimals.
31+
* - The function does *not* provide precision guarantees for non-integer-valued numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) data type for storing numbers having decimals.
3232
*
3333
* @param value - scalar value
3434
* @returns array data type
@@ -48,7 +48,7 @@ declare function minDataType( value: number ): RealDataType;
4848
*
4949
* ## Notes
5050
*
51-
* - The function does *not* provide precision guarantees for non-integer-valued real numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) data type for storing numbers having decimals.
51+
* - The function does *not* provide precision guarantees for non-integer-valued numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) data type for storing numbers having decimals.
5252
*
5353
* @param value - scalar value
5454
* @returns array data type
@@ -63,12 +63,24 @@ declare function minDataType( value: number ): RealDataType;
6363
*/
6464
declare function minDataType( value: ComplexLike ): ComplexFloatingPointDataType;
6565

66+
/**
67+
* Returns the minimum array data type of the closest "kind" necessary for storing a provided scalar value.
68+
*
69+
* @param value - scalar value
70+
* @returns array data type
71+
*
72+
* @example
73+
* var dt = minDataType( true );
74+
* // returns 'bool'
75+
*/
76+
declare function minDataType( value: boolean ): BooleanDataType;
77+
6678
/**
6779
* Returns the minimum array data type of the closest "kind" necessary for storing a provided scalar value.
6880
*
6981
* ## Notes
7082
*
71-
* - The function does *not* provide precision guarantees for non-integer-valued real numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) data type for storing numbers having decimals.
83+
* - The function does *not* provide precision guarantees for non-integer-valued numbers. In other words, the function returns the smallest possible floating-point (i.e., inexact) data type for storing numbers having decimals.
7284
*
7385
* @param value - scalar value
7486
* @returns array data type

lib/node_modules/@stdlib/array/min-dtype/docs/types/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import minDataType = require( './index' );
3030

3131
minDataType( 2.13 ); // $ExpectType RealDataType
3232
minDataType( z ); // $ExpectType ComplexFloatingPointDataType
33+
minDataType( true ); // $ExpectType "bool"
3334
minDataType( 'beep' ); // $ExpectType "generic"
3435
}
3536

lib/node_modules/@stdlib/array/min-dtype/lib/main.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
2020

2121
// MODULES //
2222

23+
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2325
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
2426
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2527
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
@@ -84,7 +86,10 @@ function minFloatDataType( value ) {
8486
* // returns 'uint8'
8587
*/
8688
function minDataType( value ) {
87-
if ( typeof value !== 'number' ) {
89+
if ( !isNumber( value ) ) {
90+
if ( isBoolean( value ) ) {
91+
return 'bool';
92+
}
8893
if ( isComplexLike( value ) ) {
8994
if ( minFloatDataType( value.re ) === 'float64' || minFloatDataType( value.im ) === 'float64' ) {
9095
return 'complex128';

lib/node_modules/@stdlib/array/min-dtype/test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -179,8 +179,8 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
179179
'float32',
180180
'generic',
181181
'generic',
182-
'generic',
183-
'generic',
182+
'bool',
183+
'bool',
184184
'generic',
185185
'complex64',
186186
'complex64',

0 commit comments

Comments
 (0)