@khanacademy/perseus 89.0.0 → 90.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-register-all-widgets-for-testing-CIrzECVC.js → chunk-register-all-widgets-for-testing-osawsgz8.js} +9 -9
- package/dist/chunk-register-all-widgets-for-testing-osawsgz8.js.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/perseus-api.d.ts +0 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.new.d.ts +8 -3
- package/dist/renderer.old.d.ts +8 -3
- package/dist/server-item-renderer.d.ts +62 -9
- package/dist/testing/item-renderer-hooks.d.ts +2 -2
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +30 -6
- package/dist/testing.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/widgets/image/utils.d.ts +0 -6
- package/dist/widgets/input-number/input-number.d.ts +1 -0
- package/dist/widgets/interactive-graphs/interactive-graph.d.ts +1 -0
- package/dist/widgets/mock-widgets/mock-widget.d.ts +1 -0
- package/dist/widgets/sorter/index.d.ts +1 -0
- package/package.json +7 -7
- package/dist/chunk-register-all-widgets-for-testing-CIrzECVC.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ export { extractWidgetIds } from "./util/extract-widget-ids";
|
|
|
109
109
|
* Types
|
|
110
110
|
*/
|
|
111
111
|
export type { ILogger, LogErrorOptions } from "./logging/log";
|
|
112
|
-
export type {
|
|
112
|
+
export type { ServerItemRenderer as ServerItemRendererComponent } from "./server-item-renderer";
|
|
113
113
|
export type { APIOptions,
|
|
114
114
|
/** @hidden */
|
|
115
115
|
APIOptionsWithDefaults,
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { B as ButtonGroup, G as Graphie, H as HUD, I as Icon, a as InlineIcon, M as MathInput, b as MultiButtonGroup, N as NumberInput, R as RangeInput, S as SvgImage, T as TextInput, r as registerWidgets, c as basicWidgets, e as extraWidgets, d as replaceDeprecatedWidgets, P as PerseusI18nContext, A as ApiOptions, C as ClassNames, j as jsxRuntimeExports, U as UserInputManager, f as Renderer, D as DependenciesContext, g as Util, h as getDependencies, J as JiptParagraphs, i as hintPaddingInlineStart, k as hintBorderWidth, m as mediaQueries, s as sharedStyles, l as context$1, n as getWidgetTypeByWidgetId, o as getWidgetExport, p as PerseusMarkdown, t as typeToButton, q as getEquationString, u as defaultPlotProps, v as chooseType, w as DEFAULT_GRAPHER_PROPS } from './chunk-register-all-widgets-for-testing-
|
|
2
|
-
export { L as Categorizer, $ as Dependencies, E as Expression, X as GrapherWidget, z as InputNumber, O as InteractiveGraphWidget, a5 as KhanColors, a0 as Log, a1 as MathRenderingContext, Q as MatrixWidget, F as NumericInput, a3 as PerseusI18nContextProvider, W as PlotterWidget, K as Radio, V as TableWidget, x as Widgets, _ as bodyXsmallBold, a8 as containerSizeClass, ac as contentHasWidgetType, at as deriveUserInputFromSerializedState, af as getAbsoluteValueCoords, as as getAngleCoords, ag as getCircleCoords, ah as getExponentialCoords, a9 as getInteractiveBoxFromSizeClass, aj as getLineCoords, ak as getLinearSystemCoords, ai as getLogarithmCoords, al as getPointCoords, am as getPolygonCoords, ar as getQuadraticCoords, an as getSegmentCoords, ao as getSinusoidCoords, ap as getTangentCoords, aq as getVectorCoords, ad as getWidgetFromWidgetMap, ab as getWidgetSubTypeByWidgetId, ae as getWidgetsFromWidgetMap, Y as iconChevronDown, Z as iconTrash, a2 as interactiveSizes, aa as mathOnlyParser, au as parseDataFromJSONP, a6 as preprocessTex, a7 as registerAllWidgetsForTesting, a4 as usePerseusI18n, y as widgets } from './chunk-register-all-widgets-for-testing-
|
|
1
|
+
import { B as ButtonGroup, G as Graphie, H as HUD, I as Icon, a as InlineIcon, M as MathInput, b as MultiButtonGroup, N as NumberInput, R as RangeInput, S as SvgImage, T as TextInput, r as registerWidgets, c as basicWidgets, e as extraWidgets, d as replaceDeprecatedWidgets, P as PerseusI18nContext, A as ApiOptions, C as ClassNames, j as jsxRuntimeExports, U as UserInputManager, f as Renderer, D as DependenciesContext, g as Util, h as getDependencies, J as JiptParagraphs, i as hintPaddingInlineStart, k as hintBorderWidth, m as mediaQueries, s as sharedStyles, l as context$1, n as getWidgetTypeByWidgetId, o as getWidgetExport, p as PerseusMarkdown, t as typeToButton, q as getEquationString, u as defaultPlotProps, v as chooseType, w as DEFAULT_GRAPHER_PROPS } from './chunk-register-all-widgets-for-testing-osawsgz8.js';
|
|
2
|
+
export { L as Categorizer, $ as Dependencies, E as Expression, X as GrapherWidget, z as InputNumber, O as InteractiveGraphWidget, a5 as KhanColors, a0 as Log, a1 as MathRenderingContext, Q as MatrixWidget, F as NumericInput, a3 as PerseusI18nContextProvider, W as PlotterWidget, K as Radio, V as TableWidget, x as Widgets, _ as bodyXsmallBold, a8 as containerSizeClass, ac as contentHasWidgetType, at as deriveUserInputFromSerializedState, af as getAbsoluteValueCoords, as as getAngleCoords, ag as getCircleCoords, ah as getExponentialCoords, a9 as getInteractiveBoxFromSizeClass, aj as getLineCoords, ak as getLinearSystemCoords, ai as getLogarithmCoords, al as getPointCoords, am as getPolygonCoords, ar as getQuadraticCoords, an as getSegmentCoords, ao as getSinusoidCoords, ap as getTangentCoords, aq as getVectorCoords, ad as getWidgetFromWidgetMap, ab as getWidgetSubTypeByWidgetId, ae as getWidgetsFromWidgetMap, Y as iconChevronDown, Z as iconTrash, a2 as interactiveSizes, aa as mathOnlyParser, au as parseDataFromJSONP, a6 as preprocessTex, a7 as registerAllWidgetsForTesting, a4 as usePerseusI18n, y as widgets } from './chunk-register-all-widgets-for-testing-osawsgz8.js';
|
|
3
3
|
import { addLibraryVersionToPerseusDebug } from '@khanacademy/perseus-utils';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { createElement } from 'react';
|
|
6
6
|
import * as PerseusLinter from '@khanacademy/perseus-linter';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
8
|
import { StyleSheet, css } from 'aphrodite';
|
|
9
|
-
import invariant from 'tiny-invariant';
|
|
10
9
|
import _ from 'underscore';
|
|
11
10
|
import Button from '@khanacademy/wonder-blocks-button';
|
|
12
11
|
import { semanticColor, sizing } from '@khanacademy/wonder-blocks-tokens';
|
|
@@ -51,6 +50,7 @@ import '@phosphor-icons/core/regular/caret-down.svg';
|
|
|
51
50
|
import '@phosphor-icons/core/regular/caret-up.svg';
|
|
52
51
|
import '@khanacademy/wonder-blocks-labeled-field';
|
|
53
52
|
import '@phosphor-icons/core/regular/warning-circle.svg';
|
|
53
|
+
import 'tiny-invariant';
|
|
54
54
|
import 'mafs';
|
|
55
55
|
import '@khanacademy/kas';
|
|
56
56
|
import '@use-gesture/react';
|
|
@@ -83,7 +83,7 @@ var components = /*#__PURE__*/Object.freeze({
|
|
|
83
83
|
|
|
84
84
|
const init=function(){registerWidgets(basicWidgets);registerWidgets(extraWidgets);replaceDeprecatedWidgets();};
|
|
85
85
|
|
|
86
|
-
const libName="@khanacademy/perseus";const libVersion="
|
|
86
|
+
const libName="@khanacademy/perseus";const libVersion="90.0.0";addLibraryVersionToPerseusDebug(libName,libVersion);
|
|
87
87
|
|
|
88
88
|
const apiVersion={major:12,minor:0};
|
|
89
89
|
|
|
@@ -95,7 +95,7 @@ class HintsRenderer extends React.Component{componentDidMount(){this._cacheHintI
|
|
|
95
95
|
|
|
96
96
|
const defaultContext={onRendered:isRendered=>{}};const context=React.createContext(defaultContext);
|
|
97
97
|
|
|
98
|
-
class ServerItemRenderer extends React.Component{componentDidMount(){this._currentFocus=null;this.maybeCallOnRendered();}componentWillUnmount(){if(this.blurTimeoutID!=null){clearTimeout(this.blurTimeoutID);this.blurTimeoutID=null;}}maybeCallOnRendered(){if(!this._fullyRendered){const assetsLoaded=Object.values(this._assetStatuses).every(Boolean);if(assetsLoaded){this._fullyRendered=true;this.props.onRendered(true);}}}_setCurrentFocus(newFocus){const{apiOptions:{isMobile,onFocusChange},keypadElement}=this.props;const prevFocus=this._currentFocus;this._currentFocus=newFocus;const inputPaths=this.getInputPaths();const didFocusInput=this._currentFocus&&inputPaths.some(inputPath=>{return Util.inputPathsEqual(inputPath,this._currentFocus)});if(onFocusChange!=null){setTimeout(()=>{const keypadDomNode=keypadElement?.getDOMNode();const keypadHeight=keypadDomNode&&didFocusInput?keypadDomNode.getBoundingClientRect().height:0;onFocusChange(this._currentFocus,prevFocus,keypadHeight,didFocusInput&&this.questionRenderer.getDOMNodeForPath(newFocus));},0);}if(keypadElement&&isMobile){if(didFocusInput){keypadElement.activate();}else {keypadElement.dismiss();}}}_onRendererBlur(blurPath){const blurringFocusPath=this._currentFocus;if(!_.isEqual(blurPath,blurringFocusPath)){return}this.blurTimeoutID=setTimeout(()=>{if(_.isEqual(this._currentFocus,blurringFocusPath)){this._setCurrentFocus(null);}},0);}focusPath(path){return this.questionRenderer.focusPath(path)}blurPath(path){return this.questionRenderer.blurPath(path)}getDOMNodeForPath(path){return this.questionRenderer.getDOMNodeForPath(path)}getInputPaths(){const questionAreaInputPaths=this.questionRenderer.getInputPaths();return questionAreaInputPaths}focus(){return this.questionRenderer.focus()}blur(){if(this._currentFocus){this.blurPath(this._currentFocus);}}getPromptJSON(){return this.questionRenderer.getPromptJSON()}getUserInput(){return this.userInput}getWidgetIds(){return this.questionRenderer.getWidgetIds()}getSerializedState(){return {question:this.questionRenderer.getSerializedState(),hints:this.hintsRenderer.getSerializedState()}}render(){const apiOptions={...ApiOptions.defaults,...this.props.apiOptions,onFocusChange:this._handleFocusChange};const contextValue={assetStatuses:this._assetStatuses,setAssetStatus:this.setAssetStatus};const questionRenderer=jsxRuntimeExports.jsx(context$1.Provider,{value:contextValue,children:jsxRuntimeExports.jsx(UserInputManager,{widgets:this.props.item.question.widgets,problemNum:this.props.problemNum??0,children:({userInput,handleUserInput,initializeUserInput})=>{this.userInput=userInput;return jsxRuntimeExports.jsx(Renderer,{keypadElement:this.props.keypadElement,problemNum:this.props.problemNum,apiOptions:apiOptions,reviewMode:this.props.reviewMode,showSolutions:this.props.showSolutions,ref:elem=>{if(elem!=null){this.questionRenderer=elem;}},content:this.props.item.question.content,widgets:this.props.item.question.widgets,images:this.props.item.question.images,linterContext:PerseusLinter.pushContextStack(this.props.linterContext,"question"),strings:this.context.strings,...this.props.dependencies,userInput:userInput,handleUserInput:(id,userInput,widgetsEmpty)=>{handleUserInput(id,userInput,widgetsEmpty);},initializeUserInput:initializeUserInput})}})});const hintsRenderer=jsxRuntimeExports.jsx(HintsRenderer,{dependencies:this.props.dependencies,hints:this.props.item.hints,hintsVisible:this.props.hintsVisible,apiOptions:apiOptions,ref:elem=>this.hintsRenderer=elem,linterContext:PerseusLinter.pushContextStack(this.props.linterContext,"hints"),strings:this.context.strings});return jsxRuntimeExports.jsx(DependenciesContext.Provider,{value:this.props.dependencies,children:jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{children:questionRenderer}),jsxRuntimeExports.jsx("div",{className:apiOptions.isMobile?undefined:css(styles.hintsContainer),children:hintsRenderer})]})})}constructor(props){super(props),this._handleFocusChange=(newFocus,oldFocus)=>{if(newFocus!=null){this._setCurrentFocus(newFocus);}else {this._onRendererBlur(oldFocus);}},this.setAssetStatus=(assetKey,status)=>{this._assetStatuses[assetKey]=status;this.maybeCallOnRendered();};this._assetStatuses={};this._fullyRendered=false;this.userInput={};}}ServerItemRenderer.contextType=PerseusI18nContext;ServerItemRenderer.defaultProps={apiOptions:{},linterContext:PerseusLinter.linterContextDefault,onRendered:isRendered=>{}};const styles=StyleSheet.create({hintsContainer:{marginInlineStart:50}});var serverItemRenderer = React.forwardRef(function ServerItemRendererWithRef(props,ref){
|
|
98
|
+
class ServerItemRenderer extends React.Component{componentDidMount(){this._currentFocus=null;this.maybeCallOnRendered();}componentWillUnmount(){if(this.blurTimeoutID!=null){clearTimeout(this.blurTimeoutID);this.blurTimeoutID=null;}}maybeCallOnRendered(){if(!this._fullyRendered){const assetsLoaded=Object.values(this._assetStatuses).every(Boolean);if(assetsLoaded){this._fullyRendered=true;this.props.onRendered(true);}}}_setCurrentFocus(newFocus){const{apiOptions:{isMobile,onFocusChange},keypadElement}=this.props;const prevFocus=this._currentFocus;this._currentFocus=newFocus;const inputPaths=this.getInputPaths();const didFocusInput=this._currentFocus&&inputPaths.some(inputPath=>{return Util.inputPathsEqual(inputPath,this._currentFocus)});if(onFocusChange!=null){setTimeout(()=>{const keypadDomNode=keypadElement?.getDOMNode();const keypadHeight=keypadDomNode&&didFocusInput?keypadDomNode.getBoundingClientRect().height:0;onFocusChange(this._currentFocus,prevFocus,keypadHeight,didFocusInput&&this.questionRenderer.getDOMNodeForPath(newFocus));},0);}if(keypadElement&&isMobile){if(didFocusInput){keypadElement.activate();}else {keypadElement.dismiss();}}}_onRendererBlur(blurPath){const blurringFocusPath=this._currentFocus;if(!_.isEqual(blurPath,blurringFocusPath)){return}this.blurTimeoutID=setTimeout(()=>{if(_.isEqual(this._currentFocus,blurringFocusPath)){this._setCurrentFocus(null);}},0);}focusPath(path){return this.questionRenderer.focusPath(path)}blurPath(path){return this.questionRenderer.blurPath(path)}getDOMNodeForPath(path){return this.questionRenderer.getDOMNodeForPath(path)}getInputPaths(){const questionAreaInputPaths=this.questionRenderer.getInputPaths();return questionAreaInputPaths}focus(){return this.questionRenderer.focus()}blur(){if(this._currentFocus){this.blurPath(this._currentFocus);}}getNumHints(){return this.props.item.hints.length}getPromptJSON(){return this.questionRenderer.getPromptJSON()}getUserInput(){return this.userInput}getWidgetIds(){return this.questionRenderer.getWidgetIds()}getSerializedState(){return {question:this.questionRenderer.getSerializedState(),hints:this.hintsRenderer.getSerializedState()}}render(){const apiOptions={...ApiOptions.defaults,...this.props.apiOptions,onFocusChange:this._handleFocusChange};const contextValue={assetStatuses:this._assetStatuses,setAssetStatus:this.setAssetStatus};const questionRenderer=jsxRuntimeExports.jsx(context$1.Provider,{value:contextValue,children:jsxRuntimeExports.jsx(UserInputManager,{widgets:this.props.item.question.widgets,problemNum:this.props.problemNum??0,children:({userInput,handleUserInput,initializeUserInput})=>{this.userInput=userInput;return jsxRuntimeExports.jsx(Renderer,{keypadElement:this.props.keypadElement,problemNum:this.props.problemNum,apiOptions:apiOptions,reviewMode:this.props.reviewMode,showSolutions:this.props.showSolutions,ref:elem=>{if(elem!=null){this.questionRenderer=elem;}},content:this.props.item.question.content,widgets:this.props.item.question.widgets,images:this.props.item.question.images,linterContext:PerseusLinter.pushContextStack(this.props.linterContext,"question"),strings:this.context.strings,...this.props.dependencies,userInput:userInput,handleUserInput:(id,userInput,widgetsEmpty)=>{handleUserInput(id,userInput,widgetsEmpty);},initializeUserInput:initializeUserInput,isScorable:true})}})});const hintsRenderer=jsxRuntimeExports.jsx(HintsRenderer,{dependencies:this.props.dependencies,hints:this.props.item.hints,hintsVisible:this.props.hintsVisible,apiOptions:apiOptions,ref:elem=>this.hintsRenderer=elem,linterContext:PerseusLinter.pushContextStack(this.props.linterContext,"hints"),strings:this.context.strings});return jsxRuntimeExports.jsx(DependenciesContext.Provider,{value:this.props.dependencies,children:jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{children:questionRenderer}),jsxRuntimeExports.jsx("div",{className:apiOptions.isMobile?undefined:css(styles.hintsContainer),children:hintsRenderer})]})})}constructor(props){super(props),this._handleFocusChange=(newFocus,oldFocus)=>{if(newFocus!=null){this._setCurrentFocus(newFocus);}else {this._onRendererBlur(oldFocus);}},this.setAssetStatus=(assetKey,status)=>{this._assetStatuses[assetKey]=status;this.maybeCallOnRendered();};this._assetStatuses={};this._fullyRendered=false;this.userInput={};}}ServerItemRenderer.contextType=PerseusI18nContext;ServerItemRenderer.defaultProps={apiOptions:{},linterContext:PerseusLinter.linterContextDefault,onRendered:isRendered=>{}};const styles=StyleSheet.create({hintsContainer:{marginInlineStart:50}});var serverItemRenderer = React.forwardRef(function ServerItemRendererWithRef(props,ref){return jsxRuntimeExports.jsx(context.Consumer,{children:({onRendered})=>jsxRuntimeExports.jsx(ServerItemRenderer,{...props,onRendered:onRendered,ref:ref})})});
|
|
99
99
|
|
|
100
100
|
function displaySigFigs(f,sigFigs,sigDecs,scientific){const s=""+f;let order=parseOrder(s);let mantissa=parseMantissa(s);let positive=parseSign(s);let add;let decAdd;let sigAdd;let zeroScientific=false;if(f==0||mantissa==""||mantissa=="0"){mantissa="";for(let i=0;i<sigFigs;i++){mantissa+="0";}order=sigFigs+sigDecs;if(sigDecs<0&&-sigDecs>=sigFigs){zeroScientific=true;}}else {decAdd=order-mantissa.length-sigDecs;sigAdd=sigFigs-mantissa.length;add=Math.min(sigAdd,decAdd);if(add<0){let rounded=round(mantissa,-add);if(rounded.length>mantissa.length+add){order++;if(decAdd>sigAdd){rounded=round(rounded,1);}}mantissa=rounded;}else if(add>0){for(let i=0;i<add;i++){mantissa+="0";}}if(mantissa==""||mantissa=="0"){mantissa="0";positive=true;order=1+sigDecs;if(order!=0){zeroScientific=true;}}}const useScientific=scientific||mantissa.length>20||order>4||order<-2||order-mantissa.length>0&&trailingZeros(mantissa)>0||zeroScientific;let returnVal="";if(!positive){returnVal+="-";}if(useScientific){returnVal+=mantissa.charAt(0);if(mantissa.length>1){returnVal+="."+mantissa.substring(1,mantissa.length);}if(order-1!=0){returnVal+=" x 10^"+(order-1);}}else {let wholePart="";let fractPart="";let needDot=true;if(order>0){if(mantissa.length>order){wholePart=mantissa.substring(0,order);fractPart=mantissa.substring(order,mantissa.length);}else {wholePart=mantissa;needDot=trailingZeros(mantissa)!=0;for(let i=0;i<order-mantissa.length;i++){wholePart+="0";}}}else {for(let i=0;i<-order;i++){fractPart+="0";}fractPart+=mantissa;}returnVal+=(wholePart==""?"0":wholePart)+(needDot?".":"")+fractPart;}return returnVal}function trailingZeros(mantissa){let zeros=0;for(let i=mantissa.length-1;i>=0;i--){const c=mantissa.charAt(i);if(c=="0"){zeros++;}else {return zeros}}return zeros}function parseSign(s){let beginning=true;let seenDot=false;let seenSomething=false;let zeros="";let all="";let pos=true;for(let i=0;i<s.length;i++){const c=s.charAt(i);if(c>="1"&&c<="9"){all+=zeros+c;zeros="";seenSomething=true;beginning=false;}else if(c=="0"){if(seenDot){if(seenSomething){all+=zeros+c;zeros="";}}else {if(seenSomething){zeros+=c;}}beginning=false;}else if(!seenDot&&c=="."){all+=zeros;zeros="";seenDot=true;beginning=false;}else if(c=="e"||c=="E"&&i+1<s.length){parseInt(s.substring(i+1,s.length));i=s.length;}else if(beginning&&(c=="+"||c=="-")){if(c=="-"){pos=!pos;}}}if(all==""){return true}return pos}function parseMantissa(s){let seenDot=false;let seenSomething=false;let zeros="";let leadZeros="";let all="";for(let i=0;i<s.length;i++){const c=s.charAt(i);if(c>="1"&&c<="9"){all+=zeros+c;zeros="";seenSomething=true;}else if(c=="0"){if(seenDot){if(seenSomething){all+=zeros+c;zeros="";}else {leadZeros+=c;}}else {if(seenSomething){leadZeros+=c;zeros+=c;}else {leadZeros+=c;}}}else if(!seenDot&&c=="."){all+=zeros;zeros="";seenDot=true;}else if(c=="e"||c=="E"&&i+1<s.length){parseInt(s.substring(i+1,s.length));i=s.length;}else ;}if(all==""){return leadZeros}return all}function parseOrder(s){let seenDot=false;let seenSomething=false;let zeros="";let all="";let decPlaces=0;let totalDecs=0;for(let i=0;i<s.length;i++){const c=s.charAt(i);if(c>="1"&&c<="9"){all+=zeros+c;zeros="";seenSomething=true;if(!seenDot){totalDecs++;decPlaces++;}}else if(c=="0"){if(seenDot){if(seenSomething){all+=zeros+c;zeros="";}else {decPlaces--;}}else {totalDecs++;if(seenSomething){decPlaces++;zeros+=c;}}}else if(!seenDot&&c=="."){all+=zeros;zeros="";seenDot=true;}else if(c=="e"||c=="E"&&i+1<s.length){const raised=parseInt(s.substring(i+1,s.length));decPlaces+=raised;totalDecs+=raised;i=s.length;}else ;}if(all==""){return totalDecs}return decPlaces}function round(mantissa,digits){const last=mantissa.length-digits-1;if(last<0){return ""}if(last>=mantissa.length-1){return mantissa}const nextToLast=mantissa.charAt(last+1);const lastChar=mantissa.charAt(last);let roundUp=false;if(nextToLast>"5"){roundUp=true;}else if(nextToLast=="5"){for(let j=last+2;j<mantissa.length;j++){if(mantissa.charAt(j)!="0"){roundUp=true;}}if(lastChar%2==1){roundUp=true;}}let result="";for(let i=last;i>=0;i--){const c=mantissa.charAt(i);if(roundUp){let nextChar;if(c=="9"){nextChar="0";}else {switch(c){case "0":nextChar="1";break;case "1":nextChar="2";break;case "2":nextChar="3";break;case "3":nextChar="4";break;case "4":nextChar="5";break;case "5":nextChar="6";break;case "6":nextChar="7";break;case "7":nextChar="8";break;case "8":nextChar="9";break}roundUp=false;}result=nextChar+result;}else {result=c+result;}}if(roundUp){result="1"+result;}return result}
|
|
101
101
|
|