Wikipedia:Reference desk/Archives/Computing/2015 June 4
Computing desk | ||
---|---|---|
< June 3 | << May | June | Jul >> | June 5 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
June 4
editForward slash in wikipedia article's name
editWhy doesn't a forward slash "/" get confused with a directory name? For example here: [[1]]. --Yppieyei (talk) 14:38, 4 June 2015 (UTC)
- The path component of URLs in http needn't be, and very often isn't, a file path. So the last element isn't a filename, and the other elements aren't directories. The browser sends, and the web server sees, that whole path as a single thing - the request looks like:
GET /wiki/HIV/AIDS_denialism HTTP/1.1 Host: en.wiki.x.io
- An http server might chose to use files and directories, but MediaWiki doesn't. Mediawiki does have special meaning for slashes inside paths - they denote subpages, except (now) the the main (article) space, where they're just regular letters (allowing article names to have slashes in them, like the one you asked about). -- Finlay McWalterᚠTalk 16:02, 4 June 2015 (UTC)
- Exactly! And modern implementations inside MediaWiki (the server software that runs Wikipedia and many other wikis) uses a complicated relational database to map between page names and the content that corresponds to those names. The page name is a string key in the database, and it gets parsed by MediaWiki per the wiki's configuration, so page names do not actually have to follow file-system or URL syntax or semantics. Slashes can be interpreted in any way that the server software sees fit: as Finlay mentions, Wikipedia's installed software is designed to interpret / to mean "treat as a subpage, unless in the Main namespace."
- Nimur (talk) 16:09, 4 June 2015 (UTC)
- See also Template:Anchor, "redirect" / ← "What links here" --Hans Haase (有问题吗) 13:24, 5 June 2015 (UTC)
How to create a 128 Bit or 64 bit floating point type in Python 3.4?
editHello, how would I create a type that can hold a 64 or 128 bit floating point number? I need to do this because I am trying to simulate real gravity in the Blender game engine(which uses Python 3.4 in the latest version). Any suggestions on how to do this? Oh and I can't write anything in C++ or C. This means that I can't write an interface library. Thanks for all your help in advance, —SGA314 (talk) 15:13, 4 June 2015 (UTC)
- Python relies on its implementation to determine floating point representation, and does not provide primitive data types for differently-sized floating point math. (There is no "single-precision" or "double precision" type in python). Review the Language Reference: Standard Types. In most implementations (like CPython) on most modern CPUs, all floating point math will be 64-bit IEEE-754 compliant representation. If you need anything else, the options are, bluntly: either do not use python, or do not use primitive data types. You can write Python code to implement any type of math you wish: you can create a class that implements 128-bit or arbitrary precision math; but the primitive types are not under your control. You can also seek out other implementations; for example, bigfloat is a third-party python package that provides arbitrary precision floating point by wrapping GNU MPFR.
- Tangentially, it is not likely that you require 128 bits to realistically model gravity in Blender. Even most numerical scientists - people who simulate physics professionally! - do not actually need or use 128 bit math, except in very specific circumstances. Can you elaborate on why you are sure that is what you want to use? Nimur (talk) 15:53, 4 June 2015 (UTC)
- Number 1, I can't use any external links outside of Wikipedia. This is because they blocked by my admin. Number 2, I am pretty sure that, like you said, python is using 64-bit numbers. However, I want to calculate Big G(the gravitational constant) which is, 6.674 * 10 ^ -11. When I type this in Blender's python console (with some modification of course), the output it gives me is, "6.674e-11," when I want, "0.00000000006674." Since Python is using a type of 64 bit, then logically I need the next step up, which is 128 bit. And number 2 question, what is a primitive data type? —SGA314 (talk) 16:17, 4 June 2015 (UTC)
- 6.674e-11 is equivalent to the decimal representation... you're unhappy with the formatted output, and not with the actual bit depth. We can help you fix that by teaching you how to use printf, which is available in Python. 64-bit and 128-bit representations have very little to do with this detail, and switching data types won't help. Don't dwell too hard on how the machine prints the number for you: what really matters is how accurately the machine actually stores the data.
- You should also read primitive data type. This knowledge is important for a programmer to have and thoroughly understand.
- It is tragic that your admin will not allow you to visit websites like Python.org (the official website for Python programming language documentation). Let me think of a way to work around this limitation: documentation may already be installed on the computer, and perhaps you don't need internet access to reach it. How did Python get on your computer? Can your administrator answer that question? Would they be willing to download the documents from the official website and provide them to you for offline use?
- Nimur (talk) 16:24, 4 June 2015 (UTC)
- A. So how would I use the printf function in Python to reformat the output? B. Python is bundled with Blender (I am using Blender version 2.74) And I doubt that Python has the documentation built in as the bundled Python package is striped down big time. That's ok though. I just remembered that I already have the full documentation downloaded for offline use. So I'm good there. —SGA314 (talk) 16:34, 4 June 2015 (UTC)
- Python doesn't have a function named printf, but (as the printf article explains) it has the % operator with a syntax similar to C's printf. I don't know how to make Python automatically print the right number of significant figures but not use the exponential (e) notation. You can manually specify a number of places after the decimal point like this:
- A. So how would I use the printf function in Python to reformat the output? B. Python is bundled with Blender (I am using Blender version 2.74) And I doubt that Python has the documentation built in as the bundled Python package is striped down big time. That's ok though. I just remembered that I already have the full documentation downloaded for offline use. So I'm good there. —SGA314 (talk) 16:34, 4 June 2015 (UTC)
- Number 1, I can't use any external links outside of Wikipedia. This is because they blocked by my admin. Number 2, I am pretty sure that, like you said, python is using 64-bit numbers. However, I want to calculate Big G(the gravitational constant) which is, 6.674 * 10 ^ -11. When I type this in Blender's python console (with some modification of course), the output it gives me is, "6.674e-11," when I want, "0.00000000006674." Since Python is using a type of 64 bit, then logically I need the next step up, which is 128 bit. And number 2 question, what is a primitive data type? —SGA314 (talk) 16:17, 4 June 2015 (UTC)
>>> print("%.14f" % 6.674e-11) 0.00000000006674
- But I don't see the point. It doesn't make the number different. You should just learn to read the standard notation. -- BenRG (talk) 19:58, 4 June 2015 (UTC)
- Ah thank you. I though the different display was because it had a lack of bit depth. But as I have been told, it dosen't matter. Thanks —SGA314 (talk) 13:39, 5 June 2015 (UTC)
- But I don't see the point. It doesn't make the number different. You should just learn to read the standard notation. -- BenRG (talk) 19:58, 4 June 2015 (UTC)