Files
secondo/apis/python2/SecondoAPI/.ipynb_checkpoints/PReal-checkpoint.ipynb

114 lines
2.7 KiB
Plaintext
Raw Normal View History

2026-01-23 17:03:45 +08:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"importing Jupyter notebook from PGenType.ipynb\n",
"importing Jupyter notebook from PGenObject.ipynb\n"
]
}
],
"source": [
"import import_ipynb\n",
"from PGenType import *\n",
"from PGenObject import *\n",
"\n",
"class PReal(PGenType):\n",
" \n",
" #def __init__(self, value, defined):\n",
" # super(TypeReal, self).__init__(value, defined)\n",
" \n",
" \n",
" def __init__(self, value = None, defined = None):\n",
" if value is not None:\n",
" assert type(value) is float, 'The given value must be of Type float.'\n",
" super(PReal, self).__init__(value, defined)\n",
" \n",
" def getTypeName(self):\n",
" return 'float'\n",
" \n",
" def getTypeClass(self):\n",
" return self.__class__.__name__\n",
" \n",
" \n",
" def __str__(self):\n",
" return \"(Real \" + str(self.getValue()) + \")\"\n",
" \n",
" def parse(self, text):\n",
" value = float(text)\n",
" result = PReal(value)\n",
" return result\n",
" \n",
" def toFloat(self):\n",
" return float(self.getValue())\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#### Test\n",
"#b = PReal(4.27,True)\n",
"#print(b.getValue())\n",
"#print(b.getDefined())\n",
"#a=PReal(3.0)\n",
"#print(a.getValue())\n",
"#print(a.getDefined())\n",
"#print(a==b)\n",
"#print(a.getTypeName())\n",
"#print(a.getTypeClass())\n",
"#l=[10.95, False]\n",
"#a.InFromList(l)\n",
"#print(a.getValue())\n",
"#print(a.getDefined())\n",
"#print(a.OutToList())\n",
"#print(b.OutToList())\n",
"#print(a)\n",
"#c = a.parse(\"17.1\")\n",
"#print(c)\n",
"#a.setDefined(True)\n",
"#d = a + c\n",
"#print(d.getValue(), d.getDefined())\n",
"#d.toFloat()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}